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 Emissive { get; set; }
public float Power { get; set; }
public string[] Textures { get; set; }
public Vector2[] TexOffsets { get; set; }
public Vector2[] TexScales { get; set; }
public List<ImportedMaterialTexture> Textures { 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

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();
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);
HashSet<String^>^ SearchHierarchy();
void SearchHierarchy(ImportedFrame^ frame, HashSet<String^>^ exportFrames);
@ -77,7 +77,7 @@ namespace AssetStudio {
void ExportFrame(FbxNode* pParentNode, ImportedFrame^ frame);
void ExportMesh(FbxNode* pFrameNode, ImportedMesh^ meshList, bool normals);
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 ExportKeyframedAnimation(ImportedKeyframedAnimation^ parser, FbxString& kTakeName, FbxAnimCurveFilterUnroll* eulerFilter, float filterPrecision, bool flatInbetween);
void ExportMorphs(IImported^ imported, bool morphMask, bool flatInbetween);

View File

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

View File

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