Small fix for Reconstructing Z Channel and add keeping aspect ration when resizing.
This commit is contained in:
@@ -661,7 +661,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path
|
|||||||
if (sourceWidth != width || sourceHeight != height)
|
if (sourceWidth != width || sourceHeight != height)
|
||||||
{
|
{
|
||||||
// During resizing we need to keep texture aspect ratio
|
// During resizing we need to keep texture aspect ratio
|
||||||
const bool keepAspectRatio = false; // TODO: expose as import option
|
const bool keepAspectRatio = options.KeepAspectRatio;
|
||||||
if (keepAspectRatio)
|
if (keepAspectRatio)
|
||||||
{
|
{
|
||||||
const float aspectRatio = static_cast<float>(sourceWidth) / sourceHeight;
|
const float aspectRatio = static_cast<float>(sourceWidth) / sourceHeight;
|
||||||
@@ -729,6 +729,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path
|
|||||||
bool keepAsIs = false;
|
bool keepAsIs = false;
|
||||||
if (!options.FlipY &&
|
if (!options.FlipY &&
|
||||||
!options.InvertGreenChannel &&
|
!options.InvertGreenChannel &&
|
||||||
|
!options.ReconstructZChannel &&
|
||||||
options.Compress &&
|
options.Compress &&
|
||||||
type == ImageType::DDS &&
|
type == ImageType::DDS &&
|
||||||
mipLevels == sourceMipLevels &&
|
mipLevels == sourceMipLevels &&
|
||||||
@@ -833,7 +834,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path
|
|||||||
if (!keepAsIs & options.ReconstructZChannel)
|
if (!keepAsIs & options.ReconstructZChannel)
|
||||||
{
|
{
|
||||||
auto& timage = GET_TMP_IMG();
|
auto& timage = GET_TMP_IMG();
|
||||||
bool isunorm = (DirectX::FormatDataType(currentImage->GetMetadata().format) == DirectX::FORMAT_TYPE_UNORM) != 0;
|
bool isunorm = (DirectX::FormatDataType(sourceDxgiFormat) == DirectX::FORMAT_TYPE_UNORM) != 0;
|
||||||
result = TransformImage(currentImage->GetImages(), currentImage->GetImageCount(), currentImage->GetMetadata(),
|
result = TransformImage(currentImage->GetImages(), currentImage->GetImageCount(), currentImage->GetMetadata(),
|
||||||
[&](DirectX::XMVECTOR* outPixels, const DirectX::XMVECTOR* inPixels, size_t w, size_t y)
|
[&](DirectX::XMVECTOR* outPixels, const DirectX::XMVECTOR* inPixels, size_t w, size_t y)
|
||||||
{
|
{
|
||||||
@@ -855,7 +856,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path
|
|||||||
{
|
{
|
||||||
z = DirectX::XMVectorSqrt(DirectX::XMVectorSubtract(DirectX::g_XMOne, DirectX::XMVector2Dot(value, value)));
|
z = DirectX::XMVectorSqrt(DirectX::XMVectorSubtract(DirectX::g_XMOne, DirectX::XMVector2Dot(value, value)));
|
||||||
}
|
}
|
||||||
outPixels[j] = XMVectorSelect(value, z, s_selectz);
|
outPixels[j] = DirectX::XMVectorSelect(value, z, s_selectz);
|
||||||
}
|
}
|
||||||
}, timage);
|
}, timage);
|
||||||
if (FAILED(result))
|
if (FAILED(result))
|
||||||
|
|||||||
@@ -82,6 +82,9 @@ void TextureTool::Options::Serialize(SerializeStream& stream, const void* otherO
|
|||||||
stream.JKEY("Resize");
|
stream.JKEY("Resize");
|
||||||
stream.Bool(Resize);
|
stream.Bool(Resize);
|
||||||
|
|
||||||
|
stream.JKEY("KeepAspectRatio");
|
||||||
|
stream.Bool(KeepAspectRatio);
|
||||||
|
|
||||||
stream.JKEY("PreserveAlphaCoverage");
|
stream.JKEY("PreserveAlphaCoverage");
|
||||||
stream.Bool(PreserveAlphaCoverage);
|
stream.Bool(PreserveAlphaCoverage);
|
||||||
|
|
||||||
@@ -139,6 +142,7 @@ void TextureTool::Options::Deserialize(DeserializeStream& stream, ISerializeModi
|
|||||||
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);
|
||||||
|
KeepAspectRatio = JsonTools::GetBool(stream, "KeepAspectRatio", KeepAspectRatio);
|
||||||
PreserveAlphaCoverage = JsonTools::GetBool(stream, "PreserveAlphaCoverage", PreserveAlphaCoverage);
|
PreserveAlphaCoverage = JsonTools::GetBool(stream, "PreserveAlphaCoverage", PreserveAlphaCoverage);
|
||||||
PreserveAlphaCoverageReference = JsonTools::GetFloat(stream, "PreserveAlphaCoverageReference", PreserveAlphaCoverageReference);
|
PreserveAlphaCoverageReference = JsonTools::GetFloat(stream, "PreserveAlphaCoverageReference", PreserveAlphaCoverageReference);
|
||||||
TextureGroup = JsonTools::GetInt(stream, "TextureGroup", TextureGroup);
|
TextureGroup = JsonTools::GetInt(stream, "TextureGroup", TextureGroup);
|
||||||
|
|||||||
@@ -77,6 +77,10 @@ API_CLASS(Namespace="FlaxEngine.Tools", Static) class FLAXENGINE_API TextureTool
|
|||||||
API_FIELD(Attributes="EditorOrder(100)")
|
API_FIELD(Attributes="EditorOrder(100)")
|
||||||
bool Resize = false;
|
bool Resize = false;
|
||||||
|
|
||||||
|
// Keeps the aspect ratio when resizing.
|
||||||
|
API_FIELD(Attributes="EditorOrder(101), VisibleIf(nameof(Resize))")
|
||||||
|
bool KeepAspectRatio = false;
|
||||||
|
|
||||||
// The width of the imported texture. If Resize property is set to true then texture will be resized during the import to this value during the import, otherwise it will be ignored.
|
// The width of the imported texture. If Resize property is set to true then texture will be resized during the import to this value during the import, otherwise it will be ignored.
|
||||||
API_FIELD(Attributes="HideInEditor")
|
API_FIELD(Attributes="HideInEditor")
|
||||||
int32 SizeX = 1024;
|
int32 SizeX = 1024;
|
||||||
|
|||||||
Reference in New Issue
Block a user