This commit is contained in:
Perfare 2019-08-06 09:48:21 +08:00
parent 495b48c783
commit d335aaef9e
4 changed files with 73 additions and 55 deletions

View File

@ -134,6 +134,10 @@ namespace AssetStudio
public string Path { get; set; } public string Path { get; set; }
public List<ImportedSubmesh> SubmeshList { get; set; } public List<ImportedSubmesh> SubmeshList { get; set; }
public List<ImportedBone> BoneList { get; set; } public List<ImportedBone> BoneList { get; set; }
public bool hasNormal { get; set; }
public bool hasUV { get; set; }
public bool hasTangent { get; set; }
public bool hasColor { get; set; }
} }
public class ImportedSubmesh public class ImportedSubmesh
@ -145,17 +149,13 @@ namespace AssetStudio
public class ImportedVertex public class ImportedVertex
{ {
public Vector3 Position { get; set; } public Vector3 Vertex { get; set; }
public float[] Weights { get; set; }
public int[] BoneIndices { get; set; }
public Vector3 Normal { get; set; } public Vector3 Normal { get; set; }
public float[] UV { get; set; } public float[] UV { get; set; }
public Vector4 Tangent { get; set; } public Vector4 Tangent { get; set; }
} public Color Color { get; set; }
public float[] Weights { get; set; }
public class ImportedVertexWithColour : ImportedVertex public int[] BoneIndices { get; set; }
{
public Color Colour { get; set; }
} }
public class ImportedFace public class ImportedFace
@ -234,8 +234,6 @@ namespace AssetStudio
{ {
public float time { get; set; } public float time { get; set; }
public T value { get; set; } public T value { get; set; }
public T inSlope { get; set; }
public T outSlope { get; set; }
public ImportedKeyframe(float time, T value) public ImportedKeyframe(float time, T value)
{ {

View File

@ -76,7 +76,7 @@ namespace AssetStudio {
void SearchHierarchy(ImportedFrame^ frame, HashSet<String^>^ exportFrames); void SearchHierarchy(ImportedFrame^ frame, HashSet<String^>^ exportFrames);
void SetJointsFromImportedMeshes(bool allBones); void SetJointsFromImportedMeshes(bool allBones);
void ExportFrame(FbxNode* pParentNode, ImportedFrame^ frame); void ExportFrame(FbxNode* pParentNode, ImportedFrame^ frame);
void ExportMesh(FbxNode* pFrameNode, ImportedMesh^ meshList); void ExportMesh(FbxNode* pFrameNode, ImportedMesh^ iMesh);
FbxFileTexture* ExportTexture(ImportedTexture^ matTex); FbxFileTexture* ExportTexture(ImportedTexture^ matTex);
void ExportAnimations(bool eulerFilter, float filterValue); void ExportAnimations(bool eulerFilter, float filterValue);
void ExportKeyframedAnimation(ImportedKeyframedAnimation^ parser, FbxString& kTakeName, FbxAnimCurveFilterUnroll* eulerFilter, float filterPrecision); void ExportKeyframedAnimation(ImportedKeyframedAnimation^ parser, FbxString& kTakeName, FbxAnimCurveFilterUnroll* eulerFilter, float filterPrecision);

View File

@ -320,9 +320,9 @@ namespace AssetStudio
} }
} }
void Fbx::Exporter::ExportMesh(FbxNode* pFrameNode, ImportedMesh^ meshList) void Fbx::Exporter::ExportMesh(FbxNode* pFrameNode, ImportedMesh^ iMesh)
{ {
List<ImportedBone^>^ boneList = meshList->BoneList; List<ImportedBone^>^ boneList = iMesh->BoneList;
bool hasBones; bool hasBones;
if (exportSkins && boneList != nullptr) if (exportSkins && boneList != nullptr)
{ {
@ -365,29 +365,40 @@ namespace AssetStudio
pFrameNode->SetNodeAttribute(pMesh); pFrameNode->SetNodeAttribute(pMesh);
int vertexCount = 0; int vertexCount = 0;
for (int i = 0; i < meshList->SubmeshList->Count; i++) for (int i = 0; i < iMesh->SubmeshList->Count; i++)
{ {
vertexCount += meshList->SubmeshList[i]->VertexList->Count; vertexCount += iMesh->SubmeshList[i]->VertexList->Count;
} }
pMesh->InitControlPoints(vertexCount); pMesh->InitControlPoints(vertexCount);
FbxVector4* pControlPoints = pMesh->GetControlPoints(); FbxVector4* pControlPoints = pMesh->GetControlPoints();
FbxGeometryElementNormal* lGeometryElementNormal = pMesh->CreateElementNormal(); FbxGeometryElementNormal* lGeometryElementNormal = NULL;
lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByControlPoint); if (iMesh->hasNormal)
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eDirect); {
lGeometryElementNormal = pMesh->CreateElementNormal();
lGeometryElementNormal->SetMappingMode(FbxGeometryElement::eByControlPoint);
lGeometryElementNormal->SetReferenceMode(FbxGeometryElement::eDirect);
}
FbxGeometryElementUV* lGeometryElementUV = pMesh->CreateElementUV("UV0"); FbxGeometryElementUV* lGeometryElementUV = NULL;
lGeometryElementUV->SetMappingMode(FbxGeometryElement::eByControlPoint); if (iMesh->hasUV)
lGeometryElementUV->SetReferenceMode(FbxGeometryElement::eDirect); {
lGeometryElementUV = pMesh->CreateElementUV("UV0");
lGeometryElementUV->SetMappingMode(FbxGeometryElement::eByControlPoint);
lGeometryElementUV->SetReferenceMode(FbxGeometryElement::eDirect);
}
FbxGeometryElementTangent* lGeometryElementTangent = pMesh->CreateElementTangent(); FbxGeometryElementTangent* lGeometryElementTangent = NULL;
lGeometryElementTangent->SetMappingMode(FbxGeometryElement::eByControlPoint); if (iMesh->hasTangent)
lGeometryElementTangent->SetReferenceMode(FbxGeometryElement::eDirect); {
lGeometryElementTangent = pMesh->CreateElementTangent();
lGeometryElementTangent->SetMappingMode(FbxGeometryElement::eByControlPoint);
lGeometryElementTangent->SetReferenceMode(FbxGeometryElement::eDirect);
}
FbxGeometryElementVertexColor* lGeometryElementVertexColor = nullptr; FbxGeometryElementVertexColor* lGeometryElementVertexColor = NULL;
bool vertexColours = vertexCount > 0 && dynamic_cast<ImportedVertexWithColour^>(meshList->SubmeshList[0]->VertexList[0]) != nullptr; if (iMesh->hasColor)
if (vertexColours)
{ {
lGeometryElementVertexColor = pMesh->CreateElementVertexColor(); lGeometryElementVertexColor = pMesh->CreateElementVertexColor();
lGeometryElementVertexColor->SetMappingMode(FbxGeometryElement::eByControlPoint); lGeometryElementVertexColor->SetMappingMode(FbxGeometryElement::eByControlPoint);
@ -399,9 +410,9 @@ namespace AssetStudio
lGeometryElementMaterial->SetReferenceMode(FbxGeometryElement::eIndexToDirect); lGeometryElementMaterial->SetReferenceMode(FbxGeometryElement::eIndexToDirect);
int firstVertex = 0; int firstVertex = 0;
for (int i = 0; i < meshList->SubmeshList->Count; i++) for (int i = 0; i < iMesh->SubmeshList->Count; i++)
{ {
ImportedSubmesh^ meshObj = meshList->SubmeshList[i]; ImportedSubmesh^ meshObj = iMesh->SubmeshList[i];
List<ImportedVertex^>^ vertexList = meshObj->VertexList; List<ImportedVertex^>^ vertexList = meshObj->VertexList;
List<ImportedFace^>^ faceList = meshObj->FaceList; List<ImportedFace^>^ faceList = meshObj->FaceList;
@ -498,33 +509,39 @@ namespace AssetStudio
for (int j = 0; j < vertexList->Count; j++) for (int j = 0; j < vertexList->Count; j++)
{ {
ImportedVertex^ vertex = vertexList[j]; ImportedVertex^ iVertex = vertexList[j];
Vector3 coords = vertex->Position; Vector3 vertex = iVertex->Vertex;
pControlPoints[j + firstVertex] = FbxVector4(coords.X, coords.Y, coords.Z, 0); pControlPoints[j + firstVertex] = FbxVector4(vertex.X, vertex.Y, vertex.Z, 0);
Vector3 normal = vertex->Normal; if (iMesh->hasNormal)
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(normal.X, normal.Y, normal.Z, 0));
array<float>^ uv = vertex->UV;
if (uv != nullptr)
{ {
Vector3 normal = iVertex->Normal;
lGeometryElementNormal->GetDirectArray().Add(FbxVector4(normal.X, normal.Y, normal.Z, 0));
}
if (iMesh->hasUV)
{
array<float>^ uv = iVertex->UV;
lGeometryElementUV->GetDirectArray().Add(FbxVector2(uv[0], uv[1])); lGeometryElementUV->GetDirectArray().Add(FbxVector2(uv[0], uv[1]));
} }
Vector4 tangent = vertex->Tangent; if (iMesh->hasTangent)
lGeometryElementTangent->GetDirectArray().Add(FbxVector4(tangent.X, tangent.Y, tangent.Z, tangent.W));
if (vertexColours)
{ {
ImportedVertexWithColour^ vert = (ImportedVertexWithColour^)vertexList[j]; Vector4 tangent = iVertex->Tangent;
lGeometryElementVertexColor->GetDirectArray().Add(FbxColor(vert->Colour.R, vert->Colour.G, vert->Colour.B, vert->Colour.A)); lGeometryElementTangent->GetDirectArray().Add(FbxVector4(tangent.X, tangent.Y, tangent.Z, tangent.W));
} }
if (hasBones && vertex->BoneIndices != nullptr) if (iMesh->hasColor)
{ {
auto boneIndices = vertex->BoneIndices; auto color = iVertex->Color;
auto weights4 = vertex->Weights; lGeometryElementVertexColor->GetDirectArray().Add(FbxColor(color.R, color.G, color.B, color.A));
}
if (hasBones && iVertex->BoneIndices != nullptr)
{
auto boneIndices = iVertex->BoneIndices;
auto weights4 = iVertex->Weights;
for (int k = 0; k < 4; k++) for (int k = 0; k < 4; k++)
{ {
if (boneIndices[k] < boneList->Count && weights4[k] > 0) if (boneIndices[k] < boneList->Count && weights4[k] > 0)
@ -866,8 +883,8 @@ namespace AssetStudio
for (int j = 0; j < keyframe->VertexList->Count; j++) for (int j = 0; j < keyframe->VertexList->Count; j++)
{ {
auto index = keyframe->VertexList[j]->Index; auto index = keyframe->VertexList[j]->Index;
auto coords = keyframe->VertexList[j]->Vertex->Position; auto vertex = keyframe->VertexList[j]->Vertex->Vertex;
lVector4[index] = FbxVector4(coords.X, coords.Y, coords.Z, 0); lVector4[index] = FbxVector4(vertex.X, vertex.Y, vertex.Z, 0);
} }
} }
} }

View File

@ -305,20 +305,20 @@ namespace AssetStudio
ImportedMaterial iMat = ConvertMaterial(mat); ImportedMaterial iMat = ConvertMaterial(mat);
iSubmesh.Material = iMat.Name; iSubmesh.Material = iMat.Name;
iSubmesh.VertexList = new List<ImportedVertex>((int)submesh.vertexCount); iSubmesh.VertexList = new List<ImportedVertex>((int)submesh.vertexCount);
var vertexColours = mesh.m_Colors != null && (mesh.m_Colors.Length == mesh.m_VertexCount * 3 || mesh.m_Colors.Length == mesh.m_VertexCount * 4);
for (var j = mesh.m_SubMeshes[i].firstVertex; j < mesh.m_SubMeshes[i].firstVertex + mesh.m_SubMeshes[i].vertexCount; j++) for (var j = mesh.m_SubMeshes[i].firstVertex; j < mesh.m_SubMeshes[i].firstVertex + mesh.m_SubMeshes[i].vertexCount; j++)
{ {
var iVertex = vertexColours ? new ImportedVertexWithColour() : new ImportedVertex(); var iVertex = new ImportedVertex();
//Vertices //Vertices
int c = 3; int c = 3;
if (mesh.m_Vertices.Length == mesh.m_VertexCount * 4) if (mesh.m_Vertices.Length == mesh.m_VertexCount * 4)
{ {
c = 4; c = 4;
} }
iVertex.Position = new Vector3(-mesh.m_Vertices[j * c], mesh.m_Vertices[j * c + 1], mesh.m_Vertices[j * c + 2]); iVertex.Vertex = new Vector3(-mesh.m_Vertices[j * c], mesh.m_Vertices[j * c + 1], mesh.m_Vertices[j * c + 2]);
//Normals //Normals
if (mesh.m_Normals?.Length > 0) if (mesh.m_Normals?.Length > 0)
{ {
iMesh.hasNormal = true;
if (mesh.m_Normals.Length == mesh.m_VertexCount * 3) if (mesh.m_Normals.Length == mesh.m_VertexCount * 3)
{ {
c = 3; c = 3;
@ -330,20 +330,22 @@ namespace AssetStudio
iVertex.Normal = new Vector3(-mesh.m_Normals[j * c], mesh.m_Normals[j * c + 1], mesh.m_Normals[j * c + 2]); iVertex.Normal = new Vector3(-mesh.m_Normals[j * c], mesh.m_Normals[j * c + 1], mesh.m_Normals[j * c + 2]);
} }
//Colors //Colors
if (vertexColours) if (mesh.m_Colors?.Length > 0)
{ {
iMesh.hasColor = true;
if (mesh.m_Colors.Length == mesh.m_VertexCount * 3) if (mesh.m_Colors.Length == mesh.m_VertexCount * 3)
{ {
((ImportedVertexWithColour)iVertex).Colour = new Color(mesh.m_Colors[j * 3], mesh.m_Colors[j * 3 + 1], mesh.m_Colors[j * 3 + 2], 1.0f); iVertex.Color = new Color(mesh.m_Colors[j * 3], mesh.m_Colors[j * 3 + 1], mesh.m_Colors[j * 3 + 2], 1.0f);
} }
else else
{ {
((ImportedVertexWithColour)iVertex).Colour = new Color(mesh.m_Colors[j * 4], mesh.m_Colors[j * 4 + 1], mesh.m_Colors[j * 4 + 2], mesh.m_Colors[j * 4 + 3]); iVertex.Color = new Color(mesh.m_Colors[j * 4], mesh.m_Colors[j * 4 + 1], mesh.m_Colors[j * 4 + 2], mesh.m_Colors[j * 4 + 3]);
} }
} }
//UV //UV
if (mesh.m_UV0?.Length > 0) if (mesh.m_UV0?.Length > 0)
{ {
iMesh.hasUV = true;
if (mesh.m_UV0.Length == mesh.m_VertexCount * 2) if (mesh.m_UV0.Length == mesh.m_VertexCount * 2)
{ {
c = 2; c = 2;
@ -357,6 +359,7 @@ namespace AssetStudio
//Tangent //Tangent
if (mesh.m_Tangents != null && mesh.m_Tangents.Length == mesh.m_VertexCount * 4) if (mesh.m_Tangents != null && mesh.m_Tangents.Length == mesh.m_VertexCount * 4)
{ {
iMesh.hasTangent = true;
iVertex.Tangent = new Vector4(-mesh.m_Tangents[j * 4], mesh.m_Tangents[j * 4 + 1], mesh.m_Tangents[j * 4 + 2], -mesh.m_Tangents[j * 4 + 3]); iVertex.Tangent = new Vector4(-mesh.m_Tangents[j * 4], mesh.m_Tangents[j * 4 + 1], mesh.m_Tangents[j * 4 + 2], -mesh.m_Tangents[j * 4 + 3]);
} }
//BoneInfluence //BoneInfluence
@ -508,7 +511,7 @@ namespace AssetStudio
var sourceVertex = GetSourceVertex(iMesh.SubmeshList, (int)morphVertex.index); var sourceVertex = GetSourceVertex(iMesh.SubmeshList, (int)morphVertex.index);
destVertex.Vertex = new ImportedVertex(); destVertex.Vertex = new ImportedVertex();
var morphPos = morphVertex.vertex; var morphPos = morphVertex.vertex;
destVertex.Vertex.Position = sourceVertex.Position + new Vector3(-morphPos.X, morphPos.Y, morphPos.Z); destVertex.Vertex.Vertex = sourceVertex.Vertex + new Vector3(-morphPos.X, morphPos.Y, morphPos.Z);
if (shape.hasNormals) if (shape.hasNormals)
{ {
var morphNormal = morphVertex.normal; var morphNormal = morphVertex.normal;