Merge branch 'plemsoft-PE-1.4-5'

This commit is contained in:
Wojtek Figat
2022-11-28 23:22:56 +01:00
5 changed files with 105 additions and 13 deletions

View File

@@ -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();
}
}

View File

@@ -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())

View File

@@ -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

View File

@@ -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

View File

@@ -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();