From b02020f8017bb4f3f22440bc39b60857ab364179 Mon Sep 17 00:00:00 2001 From: Preben Eriksen Date: Thu, 10 Nov 2022 10:51:20 +0100 Subject: [PATCH 01/13] PE: AudioSource - Stop() folowed by Play() now act like a restart. --- Source/Engine/Audio/AudioSource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/Engine/Audio/AudioSource.cpp b/Source/Engine/Audio/AudioSource.cpp index 10e2cf429..333ac2c72 100644 --- a/Source/Engine/Audio/AudioSource.cpp +++ b/Source/Engine/Audio/AudioSource.cpp @@ -132,7 +132,7 @@ void AudioSource::Play() Clip->RequestStreamingUpdate(); // If we are looping and streaming also update streaming buffers - if (_loop) + if (_loop || state == States::Stopped) RequestStreamingBuffersUpdate(); } } From 29900a3cc005f7f5ac74254d2b7a58920341d73c Mon Sep 17 00:00:00 2001 From: Preben Eriksen Date: Thu, 10 Nov 2022 11:19:29 +0100 Subject: [PATCH 02/13] PE: Support importing WAV files that contain "extra format bytes" in "fmt" header. --- Source/Engine/Tools/AudioTool/WaveDecoder.cpp | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Tools/AudioTool/WaveDecoder.cpp b/Source/Engine/Tools/AudioTool/WaveDecoder.cpp index 58adfde89..0336e965d 100644 --- a/Source/Engine/Tools/AudioTool/WaveDecoder.cpp +++ b/Source/Engine/Tools/AudioTool/WaveDecoder.cpp @@ -23,11 +23,14 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info) uint32 subChunkSize = 0; mStream->ReadUint32(&subChunkSize); + uint32 totalread = 0; + // FMT chunk if (subChunkId[0] == 'f' && subChunkId[1] == 'm' && subChunkId[2] == 't' && subChunkId[3] == ' ') { uint16 format; mStream->ReadUint16(&format); + totalread += 2; if (format != WAVE_FORMAT_PCM && format != WAVE_FORMAT_IEEE_FLOAT && format != WAVE_FORMAT_EXTENDED) { @@ -37,18 +40,23 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info) uint16 numChannels = 0; mStream->ReadUint16(&numChannels); + totalread += 2; uint32 sampleRate = 0; mStream->ReadUint32(&sampleRate); + totalread += 4; uint32 byteRate = 0; mStream->ReadUint32(&byteRate); + totalread += 4; uint16 blockAlign = 0; mStream->ReadUint16(&blockAlign); + totalread += 2; uint16 bitDepth = 0; mStream->ReadUint16(&bitDepth); + totalread += 2; if (bitDepth != 8 && bitDepth != 16 && bitDepth != 24 && bitDepth != 32) { @@ -65,6 +73,7 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info) { uint16 extensionSize = 0; mStream->ReadUint16(&extensionSize); + totalread += 2; if (extensionSize != 22) { @@ -74,12 +83,15 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info) uint16 validBitDepth = 0; mStream->ReadUint16(&validBitDepth); + totalread += 2; uint32 channelMask = 0; mStream->ReadUint32(&channelMask); + totalread += 4; uint8 subFormat[16]; mStream->Read(subFormat, sizeof(subFormat)); + totalread += 16; Platform::MemoryCopy(&format, subFormat, sizeof(format)); if (format != WAVE_FORMAT_PCM) @@ -89,10 +101,18 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info) } } + // PE: Support wav with "extra format bytes", just ignore not needed. + while (totalread < subChunkSize) + { + uint8 singlebyte; + mStream->Read(&singlebyte, sizeof(singlebyte)); + totalread++; + } + mBytesPerSample = bitDepth / 8; mFormat = format; } - // DATA chunk + // DATA chunk else if (subChunkId[0] == 'd' && subChunkId[1] == 'a' && subChunkId[2] == 't' && subChunkId[3] == 'a') { info.NumSamples = subChunkSize / mBytesPerSample; @@ -100,7 +120,7 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info) foundData = true; } - // Unsupported chunk type + // Unsupported chunk type else { if (mStream->GetPosition() + subChunkSize >= mStream->GetLength()) From 54ccf9edc7ffcda8490687ac9a4dbb4a652d4f63 Mon Sep 17 00:00:00 2001 From: Preben Eriksen Date: Thu, 10 Nov 2022 11:35:29 +0100 Subject: [PATCH 03/13] PE: Fixed - Custom animation import, frame index start and end was not the actual index but depended on frames per second. Made it impossible to use, now use the real frame index. --- Source/Engine/Tools/ModelTool/ModelTool.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index 53fd90de4..ae8e8fe7b 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -1275,8 +1275,16 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op // Trim the animation keyframes range if need to if (options.Duration == AnimationDuration::Custom) { - const float start = (float)(options.FramesRange.X / data.Animation.FramesPerSecond); - const float end = (float)(options.FramesRange.Y / data.Animation.FramesPerSecond); + // PE: This is wrong, FramesRange is Frame Index start end, not the frame time. + // PE: To extract Frame Index you has to enter Frame*FramesPerSecond or it will not work. + // PE: This also makes another problem as the "length" get wrong and your not able to loop animatons. + // const float start = (float)(options.FramesRange.X / data.Animation.FramesPerSecond); + // const float end = (float)(options.FramesRange.Y / data.Animation.FramesPerSecond); + // data.Animation.Duration = (end - start); // *data.Animation.FramesPerSecond; + + // PE: Custom animation import , frame index start and end, is now correct and the real index. + const float start = (float)(options.FramesRange.X); + const float end = (float)(options.FramesRange.Y); for (int32 i = 0; i < data.Animation.Channels.Count(); i++) { auto& anim = data.Animation.Channels[i]; @@ -1285,7 +1293,7 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op anim.Rotation.Trim(start, end); anim.Scale.Trim(start, end); } - data.Animation.Duration = (end - start) * data.Animation.FramesPerSecond; + data.Animation.Duration = (end - start); } // Change the sampling rate if need to From c73eb548c0e8967624d4cb85c8f80d230e583ef8 Mon Sep 17 00:00:00 2001 From: Preben Eriksen Date: Thu, 10 Nov 2022 13:14:19 +0100 Subject: [PATCH 04/13] PE: FBX Import - Improved normal map detection using diffuse name, if normap map was not setup inside object. --- .../Tools/ModelTool/ModelTool.OpenFBX.cpp | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp b/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp index 05681aadc..cea29f7fb 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp @@ -229,6 +229,57 @@ struct OpenFbxImporterData ImportMaterialTexture(result, mat, ofbx::Texture::EMISSIVE, material.Emissive.TextureIndex, TextureEntry::TypeHint::ColorRGB); ImportMaterialTexture(result, mat, ofbx::Texture::NORMAL, material.Normals.TextureIndex, TextureEntry::TypeHint::Normals); + // PE: FBX dont always store normal maps inside the object. + if (material.Diffuse.TextureIndex != -1 && material.Normals.TextureIndex == -1) + { + // PE: If missing , try to locate a normal map in the same path as the diffuse. + const String srcFolder = String(StringUtils::GetDirectoryName(result.Textures[material.Diffuse.TextureIndex].FilePath)); + const String srcName = StringUtils::GetFileNameWithoutExtension(result.Textures[material.Diffuse.TextureIndex].FilePath); + String srcSearch; + + const int32 num = srcName.FindLast('_'); + String srcSmallName = srcName; + if (num != -1) + { + srcSmallName = srcName.Substring(0, num); + } + + bool bNormal = false; + for (int iext = 0; iext < 6; iext++) + { + String sext = TEXT(".dds"); + if (iext == 1) sext = TEXT(".png"); + if (iext == 2) sext = TEXT(".jpg"); + if (iext == 3) sext = TEXT(".jpeg"); + if (iext == 4) sext = TEXT(".tif"); + if (iext == 5) sext = TEXT(".tga"); + for (int i = 0; i < 5; i++) + { + String sfind = TEXT("_normal" + sext); + if (i == 1) sfind = TEXT("_n" + sext); + if (i == 2) sfind = TEXT("_nm" + sext); + if (i == 3) sfind = TEXT("_nmp" + sext); + if (i == 4) sfind = TEXT("_nor" + sext); + srcSearch = srcFolder + TEXT("/") + srcSmallName + sfind; + if (FileSystem::FileExists(srcSearch)) + { + bNormal = true; + break; + } + } + if (bNormal) + break; + } + if (bNormal) + { + auto& texture = result.Textures.AddOne(); + texture.FilePath = srcSearch; + texture.Type = TextureEntry::TypeHint::Normals; + texture.AssetID = Guid::Empty; + material.Normals.TextureIndex = result.Textures.Count() - 1; + } + } + if (material.Diffuse.TextureIndex != -1) { // Detect using alpha mask in diffuse texture From c26e0f5923bd44a0356dab8064db3e2fadecd972 Mon Sep 17 00:00:00 2001 From: Preben Eriksen Date: Thu, 10 Nov 2022 13:41:40 +0100 Subject: [PATCH 05/13] PE: DDS - Improve import time if source already has mipmaps and are compressed. --- .../TextureTool/TextureTool.DirectXTex.cpp | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp index b58dd878a..540c8e186 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp @@ -623,8 +623,21 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path sliceData.Mips.Resize(mipLevels); } + bool bKeepAsIs = false; + if (!options.FlipY &&options.Compress && type == ImageType::DDS && mipLevels == sourceMipLevels && DirectX::IsCompressed(sourceDxgiFormat)) + { + if (!DirectX::IsSRGB(sourceDxgiFormat)) + { + // PE: Keep image in the current compressed format (artist choice) so we dont have to run the slow mipmap generation. + // PE: Also converting a BC1 normal map to BC5 will not improve it but just use double gpu mem. + bKeepAsIs = true; + targetDxgiFormat = sourceDxgiFormat; + targetFormat = ToPixelFormat(currentImage->GetMetadata().format); + } + } + // Decompress if texture is compressed (next steps need decompressed input data, for eg. mip maps generation or format changing) - if (DirectX::IsCompressed(sourceDxgiFormat)) + if (!bKeepAsIs && DirectX::IsCompressed(sourceDxgiFormat)) { auto& tmpImg = GET_TMP_IMG(); @@ -640,7 +653,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Fix sRGB problem - if (DirectX::IsSRGB(sourceDxgiFormat)) + if (!bKeepAsIs && DirectX::IsSRGB(sourceDxgiFormat)) { sourceDxgiFormat = ToDxgiFormat(PixelFormatExtensions::ToNonsRGB(ToPixelFormat(sourceDxgiFormat))); ((DirectX::TexMetadata&)currentImage->GetMetadata()).format = sourceDxgiFormat; @@ -649,7 +662,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Remove alpha if source texture has it but output should not, valid for compressed output only (DirectX seams to use alpha to pre-multiply colors because BC1 format has no place for alpha) - if (DirectX::HasAlpha(sourceDxgiFormat) && options.Type == TextureFormatType::ColorRGB && options.Compress) + if (!bKeepAsIs && DirectX::HasAlpha(sourceDxgiFormat) && options.Type == TextureFormatType::ColorRGB && options.Compress) { auto& tmpImg = GET_TMP_IMG(); @@ -674,7 +687,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Check flip/rotate source image - if (options.FlipY) + if (!bKeepAsIs && options.FlipY) { auto& tmpImg = GET_TMP_IMG(); @@ -691,7 +704,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Generate mip maps chain - if (useMipLevels && options.GenerateMipMaps) + if (!bKeepAsIs && useMipLevels && options.GenerateMipMaps) { auto& tmpImg = GET_TMP_IMG(); @@ -714,7 +727,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Preserve mipmap alpha coverage (if requested) - if (DirectX::HasAlpha(currentImage->GetMetadata().format) && options.PreserveAlphaCoverage && useMipLevels) + if (!bKeepAsIs && DirectX::HasAlpha(currentImage->GetMetadata().format) && options.PreserveAlphaCoverage && useMipLevels) { auto& tmpImg = GET_TMP_IMG(); @@ -746,7 +759,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path ASSERT((int32)currentImage->GetMetadata().mipLevels >= mipLevels); // Compress mip maps or convert image - if (targetDxgiFormat != sourceDxgiFormat) + if (!bKeepAsIs && targetDxgiFormat != sourceDxgiFormat) { auto& tmpImg = GET_TMP_IMG(); From 66ce8abe0156d014c5bbf49e06e8b55cab6fd623 Mon Sep 17 00:00:00 2001 From: Ruan Lucas <79365912+RuanLucasGD@users.noreply.github.com> Date: Thu, 24 Nov 2022 23:58:24 -0400 Subject: [PATCH 06/13] Adds side mouse button shortcuts to the Content window --- Source/Editor/Windows/ContentWindow.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 90cd77d11..3cac8c434 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -895,6 +895,16 @@ namespace FlaxEditor.Windows } } + /// + public override bool OnMouseDown(Float2 location, MouseButton button) + { + // Navigate through directories using the side mouse buttons + if (button == MouseButton.Extended1) NavigateBackward(); + else if (button == MouseButton.Extended2) NavigateForward(); + + return base.OnMouseDown(location, button); + } + /// public override bool OnMouseUp(Float2 location, MouseButton button) { From 8707d658f1fa929d7b129822fe4f957363771855 Mon Sep 17 00:00:00 2001 From: Tryibion Date: Fri, 25 Nov 2022 15:13:25 -0600 Subject: [PATCH 07/13] Added ability to drag maximized panels. --- Source/Editor/GUI/Docking/FloatWindowDockPanel.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs b/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs index c8e0a2b2e..f892c8237 100644 --- a/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs +++ b/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs @@ -53,8 +53,14 @@ namespace FlaxEditor.GUI.Docking // Check if window is maximized if (_window.IsMaximized) - return; - + { + // Restore window and set position to mouse. + var mousePos = _window.MousePosition; + var previousSize = _window.Size; + _window.Restore(); + _window.Window.Position = FlaxEngine.Input.MouseScreenPosition - mousePos * _window.Size / previousSize; + } + // Create docking hint window DockHintWindow.Create(this); } From 7cfde78198d9b30ac3cc6eb8fa148f4b379e98b4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Sun, 27 Nov 2022 21:05:20 +0100 Subject: [PATCH 08/13] Code style fix --- Source/Editor/Windows/ContentWindow.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.cs b/Source/Editor/Windows/ContentWindow.cs index 3cac8c434..22808a1f1 100644 --- a/Source/Editor/Windows/ContentWindow.cs +++ b/Source/Editor/Windows/ContentWindow.cs @@ -131,7 +131,7 @@ namespace FlaxEditor.Windows ScrollBars = ScrollBars.Both, Parent = _split.Panel1, }; - + // Content structure tree _tree = new Tree(false) { @@ -179,7 +179,7 @@ namespace FlaxEditor.Windows ScrollBars = ScrollBars.Vertical, Parent = _split.Panel2, }; - + // Content View _view = new ContentView { @@ -899,8 +899,10 @@ namespace FlaxEditor.Windows public override bool OnMouseDown(Float2 location, MouseButton button) { // Navigate through directories using the side mouse buttons - if (button == MouseButton.Extended1) NavigateBackward(); - else if (button == MouseButton.Extended2) NavigateForward(); + if (button == MouseButton.Extended1) + NavigateBackward(); + else if (button == MouseButton.Extended2) + NavigateForward(); return base.OnMouseDown(location, button); } From 4a9a01a89e5161f8adbd1336559809285dc9b068 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 27 Nov 2022 14:23:01 -0600 Subject: [PATCH 09/13] Moved check and ops to also fix issue #683 --- Source/Editor/GUI/Docking/DockHintWindow.cs | 10 ++++++++++ Source/Editor/GUI/Docking/FloatWindowDockPanel.cs | 10 ---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Source/Editor/GUI/Docking/DockHintWindow.cs b/Source/Editor/GUI/Docking/DockHintWindow.cs index 50be41766..0f7780ae9 100644 --- a/Source/Editor/GUI/Docking/DockHintWindow.cs +++ b/Source/Editor/GUI/Docking/DockHintWindow.cs @@ -37,6 +37,16 @@ namespace FlaxEditor.GUI.Docking // Focus window window.Focus(); + // Check if window is maximized and restore window. + if (window.IsMaximized) + { + // Restore window and set position to mouse. + var mousePos = window.MousePosition; + var previousSize = window.Size; + window.Restore(); + window.Position = FlaxEngine.Input.MouseScreenPosition - mousePos * window.Size / previousSize; + } + // Calculate dragging offset and move window to the destination position var mouseScreenPosition = FlaxEngine.Input.MouseScreenPosition; diff --git a/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs b/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs index f892c8237..07585d4cd 100644 --- a/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs +++ b/Source/Editor/GUI/Docking/FloatWindowDockPanel.cs @@ -51,16 +51,6 @@ namespace FlaxEditor.GUI.Docking if (_window == null) return; - // Check if window is maximized - if (_window.IsMaximized) - { - // Restore window and set position to mouse. - var mousePos = _window.MousePosition; - var previousSize = _window.Size; - _window.Restore(); - _window.Window.Position = FlaxEngine.Input.MouseScreenPosition - mousePos * _window.Size / previousSize; - } - // Create docking hint window DockHintWindow.Create(this); } From db6aab1cf6142be4bcfc872a99f381af9986508a Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 28 Nov 2022 20:34:26 +0100 Subject: [PATCH 10/13] Fix regression in memory allocators --- Source/Engine/Core/Memory/Allocation.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Engine/Core/Memory/Allocation.h b/Source/Engine/Core/Memory/Allocation.h index 9ae127805..80da810a8 100644 --- a/Source/Engine/Core/Memory/Allocation.h +++ b/Source/Engine/Core/Memory/Allocation.h @@ -105,7 +105,9 @@ public: FORCE_INLINE int32 CalculateCapacityGrow(int32 capacity, int32 minCapacity) const { - if (capacity == 0) + if (capacity < minCapacity) + capacity = minCapacity; + if (capacity < 8) { capacity = 8; } @@ -120,8 +122,6 @@ public: capacity |= capacity >> 16; capacity = (capacity + 1) * 2; } - if (capacity < minCapacity) - capacity = minCapacity; return capacity; } From 69ad8bc67202a642fed53f47149977155e5ed96c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 28 Nov 2022 20:34:50 +0100 Subject: [PATCH 11/13] Fix tests hanging if scripting compilation fails (eg. build tool issue) --- Source/Engine/Tests/TestMain.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Source/Engine/Tests/TestMain.cpp b/Source/Engine/Tests/TestMain.cpp index 6dd3c8873..68998e3e0 100644 --- a/Source/Engine/Tests/TestMain.cpp +++ b/Source/Engine/Tests/TestMain.cpp @@ -26,6 +26,13 @@ TestsRunnerService TestsRunnerServiceInstance; void TestsRunnerService::Update() { + // End if failed to perform a startup + if (ScriptsBuilder::LastCompilationFailed()) + { + Engine::RequestExit(-1); + return; + } + // Wait for Editor to be ready for running tests (eg. scripting loaded) if (!ScriptsBuilder::IsReady() || !Scripting::IsEveryAssemblyLoaded() || From 3f3697fbfa706144364b1c4e197ba843f00f55ed Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 28 Nov 2022 23:35:27 +0100 Subject: [PATCH 12/13] Code style cleanup #837 --- Source/Engine/Tools/AudioTool/WaveDecoder.cpp | 4 +- .../Tools/ModelTool/ModelTool.OpenFBX.cpp | 52 +++++++++++-------- Source/Engine/Tools/ModelTool/ModelTool.cpp | 16 ++---- .../TextureTool/TextureTool.DirectXTex.cpp | 16 +++--- 4 files changed, 41 insertions(+), 47 deletions(-) diff --git a/Source/Engine/Tools/AudioTool/WaveDecoder.cpp b/Source/Engine/Tools/AudioTool/WaveDecoder.cpp index 0336e965d..d93891615 100644 --- a/Source/Engine/Tools/AudioTool/WaveDecoder.cpp +++ b/Source/Engine/Tools/AudioTool/WaveDecoder.cpp @@ -101,7 +101,7 @@ bool WaveDecoder::ParseHeader(AudioDataInfo& info) } } - // PE: Support wav with "extra format bytes", just ignore not needed. + // Support wav with "extra format bytes", just ignore not needed. while (totalread < subChunkSize) { uint8 singlebyte; @@ -167,7 +167,7 @@ void WaveDecoder::Read(byte* samples, uint32 numSamples) samples[i] = *((uint8*)&val); } } - // IEEE float need to be converted into signed PCM data + // IEEE float need to be converted into signed PCM data else if (mFormat == WAVE_FORMAT_IEEE_FLOAT) { AudioTool::ConvertFromFloat((const float*)samples, (int32*)samples, numSamples); diff --git a/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp b/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp index cea29f7fb..493068892 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.OpenFBX.cpp @@ -229,48 +229,54 @@ struct OpenFbxImporterData ImportMaterialTexture(result, mat, ofbx::Texture::EMISSIVE, material.Emissive.TextureIndex, TextureEntry::TypeHint::ColorRGB); ImportMaterialTexture(result, mat, ofbx::Texture::NORMAL, material.Normals.TextureIndex, TextureEntry::TypeHint::Normals); - // PE: FBX dont always store normal maps inside the object. + // FBX don't always store normal maps inside the object if (material.Diffuse.TextureIndex != -1 && material.Normals.TextureIndex == -1) { - // PE: If missing , try to locate a normal map in the same path as the diffuse. + // If missing, try to locate a normal map in the same path as the diffuse const String srcFolder = String(StringUtils::GetDirectoryName(result.Textures[material.Diffuse.TextureIndex].FilePath)); const String srcName = StringUtils::GetFileNameWithoutExtension(result.Textures[material.Diffuse.TextureIndex].FilePath); String srcSearch; - const int32 num = srcName.FindLast('_'); String srcSmallName = srcName; if (num != -1) - { srcSmallName = srcName.Substring(0, num); - } - bool bNormal = false; - for (int iext = 0; iext < 6; iext++) + bool isNormal = false; + for (int32 iExt = 0; iExt < 6; iExt++) { - String sext = TEXT(".dds"); - if (iext == 1) sext = TEXT(".png"); - if (iext == 2) sext = TEXT(".jpg"); - if (iext == 3) sext = TEXT(".jpeg"); - if (iext == 4) sext = TEXT(".tif"); - if (iext == 5) sext = TEXT(".tga"); - for (int i = 0; i < 5; i++) + String sExit = TEXT(".dds"); + if (iExt == 1) + sExit = TEXT(".png"); + else if (iExt == 2) + sExit = TEXT(".jpg"); + else if (iExt == 3) + sExit = TEXT(".jpeg"); + else if (iExt == 4) + sExit = TEXT(".tif"); + else if (iExt == 5) + sExit = TEXT(".tga"); + for (int32 i = 0; i < 5; i++) { - String sfind = TEXT("_normal" + sext); - if (i == 1) sfind = TEXT("_n" + sext); - if (i == 2) sfind = TEXT("_nm" + sext); - if (i == 3) sfind = TEXT("_nmp" + sext); - if (i == 4) sfind = TEXT("_nor" + sext); - srcSearch = srcFolder + TEXT("/") + srcSmallName + sfind; + String sFind = TEXT("_normal" + sExit); + if (i == 1) + sFind = TEXT("_n" + sExit); + else if (i == 2) + sFind = TEXT("_nm" + sExit); + else if (i == 3) + sFind = TEXT("_nmp" + sExit); + else if (i == 4) + sFind = TEXT("_nor" + sExit); + srcSearch = srcFolder + TEXT("/") + srcSmallName + sFind; if (FileSystem::FileExists(srcSearch)) { - bNormal = true; + isNormal = true; break; } } - if (bNormal) + if (isNormal) break; } - if (bNormal) + if (isNormal) { auto& texture = result.Textures.AddOne(); texture.FilePath = srcSearch; diff --git a/Source/Engine/Tools/ModelTool/ModelTool.cpp b/Source/Engine/Tools/ModelTool/ModelTool.cpp index ae8e8fe7b..bdd87d510 100644 --- a/Source/Engine/Tools/ModelTool/ModelTool.cpp +++ b/Source/Engine/Tools/ModelTool/ModelTool.cpp @@ -1275,25 +1275,17 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op // Trim the animation keyframes range if need to if (options.Duration == AnimationDuration::Custom) { - // PE: This is wrong, FramesRange is Frame Index start end, not the frame time. - // PE: To extract Frame Index you has to enter Frame*FramesPerSecond or it will not work. - // PE: This also makes another problem as the "length" get wrong and your not able to loop animatons. - // const float start = (float)(options.FramesRange.X / data.Animation.FramesPerSecond); - // const float end = (float)(options.FramesRange.Y / data.Animation.FramesPerSecond); - // data.Animation.Duration = (end - start); // *data.Animation.FramesPerSecond; - - // PE: Custom animation import , frame index start and end, is now correct and the real index. - const float start = (float)(options.FramesRange.X); - const float end = (float)(options.FramesRange.Y); + // Custom animation import, frame index start and end + const float start = options.FramesRange.X; + const float end = options.FramesRange.Y; for (int32 i = 0; i < data.Animation.Channels.Count(); i++) { auto& anim = data.Animation.Channels[i]; - anim.Position.Trim(start, end); anim.Rotation.Trim(start, end); anim.Scale.Trim(start, end); } - data.Animation.Duration = (end - start); + data.Animation.Duration = end - start; } // Change the sampling rate if need to diff --git a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp index 540c8e186..d25523406 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp @@ -624,16 +624,12 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } bool bKeepAsIs = false; - if (!options.FlipY &&options.Compress && type == ImageType::DDS && mipLevels == sourceMipLevels && DirectX::IsCompressed(sourceDxgiFormat)) + if (!options.FlipY && options.Compress && type == ImageType::DDS && mipLevels == sourceMipLevels && DirectX::IsCompressed(sourceDxgiFormat) && !DirectX::IsSRGB(sourceDxgiFormat)) { - if (!DirectX::IsSRGB(sourceDxgiFormat)) - { - // PE: Keep image in the current compressed format (artist choice) so we dont have to run the slow mipmap generation. - // PE: Also converting a BC1 normal map to BC5 will not improve it but just use double gpu mem. - bKeepAsIs = true; - targetDxgiFormat = sourceDxgiFormat; - targetFormat = ToPixelFormat(currentImage->GetMetadata().format); - } + // Keep image in the current compressed format (artist choice) so we don't have to run the slow mipmap generation + bKeepAsIs = true; + targetDxgiFormat = sourceDxgiFormat; + targetFormat = ToPixelFormat(currentImage->GetMetadata().format); } // Decompress if texture is compressed (next steps need decompressed input data, for eg. mip maps generation or format changing) @@ -897,7 +893,7 @@ bool TextureTool::ConvertDirectXTex(TextureData& dst, const TextureData& src, co return true; } } - // Check if convert data + // Check if convert data else if (inImage->GetMetadata().format != dstFormatDxgi) { result = DirectX::Convert(inImage->GetImages(), inImage->GetImageCount(), inImage->GetMetadata(), dstFormatDxgi, DirectX::TEX_FILTER_DEFAULT, DirectX::TEX_THRESHOLD_DEFAULT, dstImage); From 9e1692e3e0f67d49bafa27b6416f7a5fac8e11bb Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Tue, 29 Nov 2022 08:41:52 +0100 Subject: [PATCH 13/13] Code style cleanup #837 --- .../TextureTool/TextureTool.DirectXTex.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp index d25523406..4b5fb4897 100644 --- a/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp +++ b/Source/Engine/Tools/TextureTool/TextureTool.DirectXTex.cpp @@ -623,17 +623,17 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path sliceData.Mips.Resize(mipLevels); } - bool bKeepAsIs = false; + bool keepAsIs = false; if (!options.FlipY && options.Compress && type == ImageType::DDS && mipLevels == sourceMipLevels && DirectX::IsCompressed(sourceDxgiFormat) && !DirectX::IsSRGB(sourceDxgiFormat)) { // Keep image in the current compressed format (artist choice) so we don't have to run the slow mipmap generation - bKeepAsIs = true; + keepAsIs = true; targetDxgiFormat = sourceDxgiFormat; targetFormat = ToPixelFormat(currentImage->GetMetadata().format); } // Decompress if texture is compressed (next steps need decompressed input data, for eg. mip maps generation or format changing) - if (!bKeepAsIs && DirectX::IsCompressed(sourceDxgiFormat)) + if (!keepAsIs && DirectX::IsCompressed(sourceDxgiFormat)) { auto& tmpImg = GET_TMP_IMG(); @@ -649,7 +649,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Fix sRGB problem - if (!bKeepAsIs && DirectX::IsSRGB(sourceDxgiFormat)) + if (!keepAsIs && DirectX::IsSRGB(sourceDxgiFormat)) { sourceDxgiFormat = ToDxgiFormat(PixelFormatExtensions::ToNonsRGB(ToPixelFormat(sourceDxgiFormat))); ((DirectX::TexMetadata&)currentImage->GetMetadata()).format = sourceDxgiFormat; @@ -658,7 +658,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Remove alpha if source texture has it but output should not, valid for compressed output only (DirectX seams to use alpha to pre-multiply colors because BC1 format has no place for alpha) - if (!bKeepAsIs && DirectX::HasAlpha(sourceDxgiFormat) && options.Type == TextureFormatType::ColorRGB && options.Compress) + if (!keepAsIs && DirectX::HasAlpha(sourceDxgiFormat) && options.Type == TextureFormatType::ColorRGB && options.Compress) { auto& tmpImg = GET_TMP_IMG(); @@ -683,7 +683,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Check flip/rotate source image - if (!bKeepAsIs && options.FlipY) + if (!keepAsIs && options.FlipY) { auto& tmpImg = GET_TMP_IMG(); @@ -700,7 +700,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Generate mip maps chain - if (!bKeepAsIs && useMipLevels && options.GenerateMipMaps) + if (!keepAsIs && useMipLevels && options.GenerateMipMaps) { auto& tmpImg = GET_TMP_IMG(); @@ -723,7 +723,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path } // Preserve mipmap alpha coverage (if requested) - if (!bKeepAsIs && DirectX::HasAlpha(currentImage->GetMetadata().format) && options.PreserveAlphaCoverage && useMipLevels) + if (!keepAsIs && DirectX::HasAlpha(currentImage->GetMetadata().format) && options.PreserveAlphaCoverage && useMipLevels) { auto& tmpImg = GET_TMP_IMG(); @@ -755,7 +755,7 @@ bool TextureTool::ImportTextureDirectXTex(ImageType type, const StringView& path ASSERT((int32)currentImage->GetMetadata().mipLevels >= mipLevels); // Compress mip maps or convert image - if (!bKeepAsIs && targetDxgiFormat != sourceDxgiFormat) + if (!keepAsIs && targetDxgiFormat != sourceDxgiFormat) { auto& tmpImg = GET_TMP_IMG();