Add FlipX to texture tool.

This commit is contained in:
Chandler Cox
2024-10-04 19:31:55 -05:00
parent 2a5de178fa
commit 305d3a6496
3 changed files with 28 additions and 5 deletions

View File

@@ -728,6 +728,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path
bool keepAsIs = false; bool keepAsIs = false;
if (!options.FlipY && if (!options.FlipY &&
!options.FlipX &&
!options.InvertGreenChannel && !options.InvertGreenChannel &&
!options.ReconstructZChannel && !options.ReconstructZChannel &&
options.Compress && options.Compress &&
@@ -788,7 +789,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path
SET_CURRENT_IMG(tmpImg); SET_CURRENT_IMG(tmpImg);
} }
// Check flip/rotate source image // Check flip/rotate Y source image
if (!keepAsIs && options.FlipY) if (!keepAsIs && options.FlipY)
{ {
auto& tmpImg = GET_TMP_IMG(); auto& tmpImg = GET_TMP_IMG();
@@ -802,6 +803,20 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path
SET_CURRENT_IMG(tmpImg); SET_CURRENT_IMG(tmpImg);
} }
// Check flip/rotate X source image
if (!keepAsIs && options.FlipX)
{
auto& tmpImg = GET_TMP_IMG();
DirectX::TEX_FR_FLAGS flags = DirectX::TEX_FR_FLIP_HORIZONTAL;
result = FlipRotate(currentImage->GetImages(), currentImage->GetImageCount(), currentImage->GetMetadata(), flags, tmpImg);
if (FAILED(result))
{
errorMsg = String::Format(TEXT("Cannot rotate/flip texture, error: {0:x}"), static_cast<uint32>(result));
return true;
}
SET_CURRENT_IMG(tmpImg);
}
// Check if invert green channel // Check if invert green channel
if (!keepAsIs && options.InvertGreenChannel) if (!keepAsIs && options.InvertGreenChannel)
{ {

View File

@@ -73,6 +73,9 @@ void TextureTool::Options::Serialize(SerializeStream& stream, const void* otherO
stream.JKEY("FlipY"); stream.JKEY("FlipY");
stream.Bool(FlipY); stream.Bool(FlipY);
stream.JKEY("FlipX");
stream.Bool(FlipX);
stream.JKEY("InvertGreenChannel"); stream.JKEY("InvertGreenChannel");
stream.Bool(InvertGreenChannel); stream.Bool(InvertGreenChannel);
@@ -139,6 +142,7 @@ void TextureTool::Options::Deserialize(DeserializeStream& stream, ISerializeModi
sRGB = JsonTools::GetBool(stream, "sRGB", sRGB); sRGB = JsonTools::GetBool(stream, "sRGB", sRGB);
GenerateMipMaps = JsonTools::GetBool(stream, "GenerateMipMaps", GenerateMipMaps); GenerateMipMaps = JsonTools::GetBool(stream, "GenerateMipMaps", GenerateMipMaps);
FlipY = JsonTools::GetBool(stream, "FlipY", FlipY); FlipY = JsonTools::GetBool(stream, "FlipY", FlipY);
FlipX = JsonTools::GetBool(stream, "FlipX", FlipX);
InvertGreenChannel = JsonTools::GetBool(stream, "InvertGreenChannel", InvertGreenChannel); InvertGreenChannel = JsonTools::GetBool(stream, "InvertGreenChannel", InvertGreenChannel);
ReconstructZChannel = JsonTools::GetBool(stream, "ReconstructZChannel", ReconstructZChannel); ReconstructZChannel = JsonTools::GetBool(stream, "ReconstructZChannel", ReconstructZChannel);
Resize = JsonTools::GetBool(stream, "Resize", Resize); Resize = JsonTools::GetBool(stream, "Resize", Resize);

View File

@@ -53,16 +53,20 @@ API_CLASS(Namespace="FlaxEngine.Tools", Static) class FLAXENGINE_API TextureTool
API_FIELD(Attributes="EditorOrder(60)") API_FIELD(Attributes="EditorOrder(60)")
bool GenerateMipMaps = true; bool GenerateMipMaps = true;
// True if flip Y coordinate of the texture. // True if flip Y coordinate of the texture (Flips over X axis).
API_FIELD(Attributes="EditorOrder(70)") API_FIELD(Attributes="EditorOrder(70)")
bool FlipY = false; bool FlipY = false;
// True if flip X coordinate of the texture (Flips over Y axis).
API_FIELD(Attributes="EditorOrder(71)")
bool FlipX = false;
// True if to invert the green channel on a normal map. Good for OpenGL to DirectX conversion. // True if to invert the green channel on a normal map. Good for OpenGL to DirectX conversion.
API_FIELD(Attributes = "EditorOrder(71)") API_FIELD(Attributes = "EditorOrder(72)")
bool InvertGreenChannel = false; bool InvertGreenChannel = false;
// Rebuild Z (blue) channel assuming X/Y are normals. // Rebuild Z (blue) channel assuming X/Y are normals.
API_FIELD(Attributes = "EditorOrder(72)") API_FIELD(Attributes = "EditorOrder(73)")
bool ReconstructZChannel = false; bool ReconstructZChannel = false;
// Texture size scale. Allows increasing or decreasing the imported texture resolution. Default is 1. // Texture size scale. Allows increasing or decreasing the imported texture resolution. Default is 1.