in unity/Assets/UnityFBXExporter/FBXUnityMaterialGetter.cs [235:324]
private static bool SerializeOneTexture(GameObject gameObj,
string newPath,
Material material,
string materialName,
int materialId,
bool copyTextures,
string unityExtension,
string textureType,
out string objects,
out string connections)
{
StringBuilder objectsSb = new StringBuilder();
StringBuilder connectionsSb = new StringBuilder();
Texture texture = material.GetTexture(unityExtension);
if(texture == null)
{
objects = "";
connections = "";
return false;
}
string originalAssetPath = "";
#if UNITY_EDITOR
originalAssetPath = AssetDatabase.GetAssetPath(texture);
#else
Debug.LogError("Unity FBX Exporter can not serialize textures at runtime (yet). Look in FBXUnityMaterialGetter around line 250ish. Fix it and contribute to the project!");
objects = "";
connections = "";
return false;
#endif
string fullDataFolderPath = Application.dataPath;
string textureFilePathFullName = originalAssetPath;
string textureName = Path.GetFileNameWithoutExtension(originalAssetPath);
string textureExtension = Path.GetExtension(originalAssetPath);
// If we are copying the textures over, we update the relative positions
if(copyTextures)
{
int indexOfAssetsFolder = fullDataFolderPath.LastIndexOf("/Assets");
fullDataFolderPath = fullDataFolderPath.Remove(indexOfAssetsFolder, fullDataFolderPath.Length - indexOfAssetsFolder);
string newPathFolder = newPath.Remove(newPath.LastIndexOf('/') + 1, newPath.Length - newPath.LastIndexOf('/') - 1);
textureName = gameObj.name + "_" + material.name + unityExtension;
textureFilePathFullName = fullDataFolderPath + "/" + newPathFolder + textureName + textureExtension;
}
long textureReference = FBXExporter.GetRandomFBXId();
// TODO - test out different reference names to get one that doesn't load a _MainTex when importing.
objectsSb.AppendLine("\tTexture: " + textureReference + ", \"Texture::" + materialName + "\", \"\" {");
objectsSb.AppendLine("\t\tType: \"TextureVideoClip\"");
objectsSb.AppendLine("\t\tVersion: 202");
objectsSb.AppendLine("\t\tTextureName: \"Texture::" + materialName + "\"");
objectsSb.AppendLine("\t\tProperties70: {");
objectsSb.AppendLine("\t\t\tP: \"CurrentTextureBlendMode\", \"enum\", \"\", \"\",0");
objectsSb.AppendLine("\t\t\tP: \"UVSet\", \"KString\", \"\", \"\", \"map1\"");
objectsSb.AppendLine("\t\t\tP: \"UseMaterial\", \"bool\", \"\", \"\",1");
objectsSb.AppendLine("\t\t}");
objectsSb.AppendLine("\t\tMedia: \"Video::" + materialName + "\"");
// Sets the absolute path for the copied texture
objectsSb.Append("\t\tFileName: \"");
objectsSb.Append(textureFilePathFullName);
objectsSb.AppendLine("\"");
// Sets the relative path for the copied texture
// TODO: If we don't copy the textures to a relative path, we must find a relative path to write down here
if(copyTextures)
objectsSb.AppendLine("\t\tRelativeFilename: \"/Textures/" + textureName + textureExtension + "\"");
objectsSb.AppendLine("\t\tModelUVTranslation: 0,0"); // TODO: Figure out how to get the UV translation into here
objectsSb.AppendLine("\t\tModelUVScaling: 1,1"); // TODO: Figure out how to get the UV scaling into here
objectsSb.AppendLine("\t\tTexture_Alpha_Source: \"None\""); // TODO: Add alpha source here if the file is a cutout.
objectsSb.AppendLine("\t\tCropping: 0,0,0,0");
objectsSb.AppendLine("\t}");
connectionsSb.AppendLine("\t;Texture::" + textureName + ", Material::" + materialName + "\"");
connectionsSb.AppendLine("\tC: \"OP\"," + textureReference + "," + materialId + ", \"" + textureType + "\"");
connectionsSb.AppendLine();
objects = objectsSb.ToString();
connections = connectionsSb.ToString();
return true;
}