This commit is contained in:
Perfare 2018-12-24 08:28:26 +08:00
parent 911272167a
commit dec0a22ffe
4 changed files with 78 additions and 73 deletions

View File

@ -168,9 +168,15 @@ namespace AssetStudio
public Color4 Specular { get; set; } public Color4 Specular { get; set; }
public Color4 Emissive { get; set; } public Color4 Emissive { get; set; }
public float Power { get; set; } public float Power { get; set; }
public string[] Textures { get; set; } public List<ImportedMaterialTexture> Textures { get; set; }
public Vector2[] TexOffsets { get; set; } }
public Vector2[] TexScales { get; set; }
public class ImportedMaterialTexture
{
public string Name { get; set; }
public int Dest { get; set; }
public Vector2 Offset { get; set; }
public Vector2 Scale { get; set; }
} }
public class ImportedTexture public class ImportedTexture

View File

@ -69,7 +69,7 @@ namespace AssetStudio {
Exporter(String^ path, IImported^ imported, bool allFrames, bool allBones, bool skins, float boneSize, float scaleFactor, int versionIndex, bool isAscii, bool normals); Exporter(String^ path, IImported^ imported, bool allFrames, bool allBones, bool skins, float boneSize, float scaleFactor, int versionIndex, bool isAscii, bool normals);
~Exporter(); ~Exporter();
void Exporter::LinkTexture(ImportedMaterial^ mat, int attIndex, FbxFileTexture* pTexture, FbxProperty& prop); void Exporter::LinkTexture(ImportedMaterialTexture^ texture, FbxFileTexture* pTexture, FbxProperty& prop);
void SetJointsNode(FbxNode* pNode, HashSet<String^>^ boneNames, bool allBones); void SetJointsNode(FbxNode* pNode, HashSet<String^>^ boneNames, bool allBones);
HashSet<String^>^ SearchHierarchy(); HashSet<String^>^ SearchHierarchy();
void SearchHierarchy(ImportedFrame^ frame, HashSet<String^>^ exportFrames); void SearchHierarchy(ImportedFrame^ frame, HashSet<String^>^ exportFrames);
@ -77,7 +77,7 @@ namespace AssetStudio {
void ExportFrame(FbxNode* pParentNode, ImportedFrame^ frame); void ExportFrame(FbxNode* pParentNode, ImportedFrame^ frame);
void ExportMesh(FbxNode* pFrameNode, ImportedMesh^ meshList, bool normals); void ExportMesh(FbxNode* pFrameNode, ImportedMesh^ meshList, bool normals);
FbxNode* FindNodeByPath(String ^ path, bool recursive); FbxNode* FindNodeByPath(String ^ path, bool recursive);
FbxFileTexture* ExportTexture(ImportedTexture^ matTex, FbxMesh* pMesh); FbxFileTexture* ExportTexture(ImportedTexture^ matTex);
void ExportAnimations(bool eulerFilter, float filterValue, bool flatInbetween); void ExportAnimations(bool eulerFilter, float filterValue, bool flatInbetween);
void ExportKeyframedAnimation(ImportedKeyframedAnimation^ parser, FbxString& kTakeName, FbxAnimCurveFilterUnroll* eulerFilter, float filterPrecision, bool flatInbetween); void ExportKeyframedAnimation(ImportedKeyframedAnimation^ parser, FbxString& kTakeName, FbxAnimCurveFilterUnroll* eulerFilter, float filterPrecision, bool flatInbetween);
void ExportMorphs(IImported^ imported, bool morphMask, bool flatInbetween); void ExportMorphs(IImported^ imported, bool morphMask, bool flatInbetween);

View File

@ -474,39 +474,49 @@ namespace AssetStudio
pMeshNode->AddMaterial(pMat); pMeshNode->AddMaterial(pMat);
bool hasTexture = false; bool hasTexture = false;
FbxFileTexture* pTextureDiffuse = ExportTexture(ImportedHelpers::FindTexture(mat->Textures[0], imported->TextureList), pMesh);
if (pTextureDiffuse != NULL)
{
LinkTexture(mat, 0, pTextureDiffuse, pMat->Diffuse);
hasTexture = true;
}
FbxFileTexture* pTextureAmbient = ExportTexture(ImportedHelpers::FindTexture(mat->Textures[1], imported->TextureList), pMesh); for each (ImportedMaterialTexture^ texture in mat->Textures)
if (pTextureAmbient != NULL)
{ {
LinkTexture(mat, 1, pTextureAmbient, pMat->Ambient); if (texture->Dest == 0)
hasTexture = true; {
} FbxFileTexture* pTextureDiffuse = ExportTexture(ImportedHelpers::FindTexture(texture->Name, imported->TextureList));
if (pTextureDiffuse != NULL)
FbxFileTexture* pTextureEmissive = ExportTexture(ImportedHelpers::FindTexture(mat->Textures[2], imported->TextureList), pMesh); {
if (pTextureEmissive != NULL) LinkTexture(texture, pTextureDiffuse, pMat->Diffuse);
{ hasTexture = true;
LinkTexture(mat, 2, pTextureEmissive, pMat->Emissive); }
hasTexture = true; }
} else if (texture->Dest == 1)
{
FbxFileTexture* pTextureSpecular = ExportTexture(ImportedHelpers::FindTexture(mat->Textures[3], imported->TextureList), pMesh); FbxFileTexture* pTextureEmissive = ExportTexture(ImportedHelpers::FindTexture(texture->Name, imported->TextureList));
if (pTextureSpecular != NULL) if (pTextureEmissive != NULL)
{ {
LinkTexture(mat, 3, pTextureSpecular, pMat->Specular); LinkTexture(texture, pTextureEmissive, pMat->Emissive);
hasTexture = true; hasTexture = true;
} }
}
FbxFileTexture* pTextureBump = ExportTexture(ImportedHelpers::FindTexture(mat->Textures[4], imported->TextureList), pMesh); else if (texture->Dest == 2)
if (pTextureBump != NULL) {
{ FbxFileTexture* pTextureSpecular = ExportTexture(ImportedHelpers::FindTexture(texture->Name, imported->TextureList));
LinkTexture(mat, 4, pTextureBump, pMat->Bump); if (pTextureSpecular != NULL)
hasTexture = true; {
LinkTexture(texture, pTextureSpecular, pMat->Specular);
hasTexture = true;
}
}
else if (texture->Dest == 3)
{
FbxFileTexture* pTextureBump = ExportTexture(ImportedHelpers::FindTexture(texture->Name, imported->TextureList));
if (pTextureBump != NULL)
{
LinkTexture(texture, pTextureBump, pMat->Bump);
hasTexture = true;
}
}
else
{
ExportTexture(ImportedHelpers::FindTexture(texture->Name, imported->TextureList));
}
} }
if (hasTexture) if (hasTexture)
@ -650,7 +660,7 @@ namespace AssetStudio
return lNode; return lNode;
} }
FbxFileTexture* Fbx::Exporter::ExportTexture(ImportedTexture^ matTex, FbxMesh* pMesh) FbxFileTexture* Fbx::Exporter::ExportTexture(ImportedTexture^ matTex)
{ {
FbxFileTexture* pTex = NULL; FbxFileTexture* pTex = NULL;
@ -714,16 +724,10 @@ namespace AssetStudio
return pTex; return pTex;
} }
void Fbx::Exporter::LinkTexture(ImportedMaterial^ mat, int attIndex, FbxFileTexture* pTexture, FbxProperty& prop) void Fbx::Exporter::LinkTexture(ImportedMaterialTexture^ texture, FbxFileTexture* pTexture, FbxProperty& prop)
{ {
if (mat->TexOffsets != nullptr) pTexture->SetTranslation(texture->Offset.X, texture->Offset.Y);
{ pTexture->SetScale(texture->Scale.X, texture->Scale.Y);
pTexture->SetTranslation(mat->TexOffsets[attIndex].X, mat->TexOffsets[attIndex].Y);
}
if (mat->TexScales != nullptr)
{
pTexture->SetScale(mat->TexScales[attIndex].X, mat->TexScales[attIndex].Y);
}
prop.ConnectSrcObject(pTexture); prop.ConnectSrcObject(pTexture);
} }

View File

@ -587,38 +587,32 @@ namespace AssetStudio
} }
//textures //textures
iMat.Textures = new string[5]; iMat.Textures = new List<ImportedMaterialTexture>();
iMat.TexOffsets = new Vector2[5];
iMat.TexScales = new Vector2[5];
foreach (var texEnv in mat.m_SavedProperties.m_TexEnvs) foreach (var texEnv in mat.m_SavedProperties.m_TexEnvs)
{ {
Texture2D m_Texture2D = null; if (!texEnv.Value.m_Texture.TryGet<Texture2D>(out var m_Texture2D)) //TODO other Texture
if (texEnv.Value.m_Texture.TryGet<Texture2D>(out var m_Texture)) //TODO other Texture
{
m_Texture2D = m_Texture;
}
if (m_Texture2D == null)
{ {
continue; continue;
} }
var texture = new ImportedMaterialTexture();
iMat.Textures.Add(texture);
int dest = -1; int dest = -1;
if (texEnv.Key == "_MainTex") if (texEnv.Key == "_MainTex")
dest = 0; dest = 0;
else if (texEnv.Key == "_BumpMap") else if (texEnv.Key == "_BumpMap")
dest = 4;
else if (texEnv.Key.Contains("Spec"))
dest = 2;
else if (texEnv.Key.Contains("Norm"))
dest = 3; dest = 3;
if (dest < 0 || iMat.Textures[dest] != null) else if (texEnv.Key.Contains("Specular"))
{ dest = 2;
continue; else if (texEnv.Key.Contains("Normal"))
} dest = 1;
if (textureNameDictionary.TryGetValue(m_Texture, out var textureName)) texture.Dest = dest;
if (textureNameDictionary.TryGetValue(m_Texture2D, out var textureName))
{ {
iMat.Textures[dest] = textureName; texture.Name = textureName;
} }
else if (ImportedHelpers.FindTexture(m_Texture2D.m_Name + ".png", TextureList) != null) //已有相同名字的图片 else if (ImportedHelpers.FindTexture(m_Texture2D.m_Name + ".png", TextureList) != null) //已有相同名字的图片
{ {
@ -627,20 +621,21 @@ namespace AssetStudio
var name = m_Texture2D.m_Name + $" ({i}).png"; var name = m_Texture2D.m_Name + $" ({i}).png";
if (ImportedHelpers.FindTexture(name, TextureList) == null) if (ImportedHelpers.FindTexture(name, TextureList) == null)
{ {
iMat.Textures[dest] = name; texture.Name = name;
textureNameDictionary.Add(m_Texture, name); textureNameDictionary.Add(m_Texture2D, name);
break; break;
} }
} }
} }
else else
{ {
iMat.Textures[dest] = m_Texture2D.m_Name + ".png"; texture.Name = m_Texture2D.m_Name + ".png";
textureNameDictionary.Add(m_Texture, iMat.Textures[dest]); textureNameDictionary.Add(m_Texture2D, texture.Name);
} }
iMat.TexOffsets[dest] = texEnv.Value.m_Offset;
iMat.TexScales[dest] = texEnv.Value.m_Scale; texture.Offset = texEnv.Value.m_Offset;
ConvertTexture2D(m_Texture2D, iMat.Textures[dest]); texture.Scale = texEnv.Value.m_Scale;
ConvertTexture2D(m_Texture2D, texture.Name);
} }
MaterialList.Add(iMat); MaterialList.Add(iMat);