Add unit test for ModelTool::DetectLodIndex and improve LOD index detection further
#765
This commit is contained in:
24
Source/Engine/Tests/TestModelTool.cpp
Normal file
24
Source/Engine/Tests/TestModelTool.cpp
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
#include "Engine/Tools/ModelTool/ModelTool.h"
|
||||
#include <ThirdParty/catch2/catch.hpp>
|
||||
|
||||
TEST_CASE("ModelTool")
|
||||
{
|
||||
SECTION("Test DetectLodIndex")
|
||||
{
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh")) == 0);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh LOD")) == 0);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh LOD0")) == 0);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh LOD1")) == 1);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh_LOD1")) == 1);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh_lod1")) == 1);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh_lod2")) == 2);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("lod0")) == 0);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("lod1")) == 1);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("lod_2")) == 2);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh_lod_0")) == 0);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh_lod_1")) == 1);
|
||||
CHECK(ModelTool::DetectLodIndex(TEXT("mesh lod_2")) == 2);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
using Flax.Build;
|
||||
using Flax.Build.NativeCpp;
|
||||
|
||||
/// <summary>
|
||||
/// Engine tests module.
|
||||
@@ -14,6 +15,14 @@ public class Tests : EngineModule
|
||||
Deploy = false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Setup(BuildOptions options)
|
||||
{
|
||||
base.Setup(options);
|
||||
|
||||
options.PrivateDependencies.Add("ModelTool");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void GetFilesToDeploy(List<string> files)
|
||||
{
|
||||
|
||||
@@ -1552,25 +1552,21 @@ bool ModelTool::ImportModel(const String& path, ModelData& meshData, Options& op
|
||||
|
||||
int32 ModelTool::DetectLodIndex(const String& nodeName)
|
||||
{
|
||||
int32 index = nodeName.FindLast(TEXT("LOD"));
|
||||
int32 index = nodeName.FindLast(TEXT("LOD"), StringSearchCase::IgnoreCase);
|
||||
if (index != -1)
|
||||
{
|
||||
int32 num;
|
||||
//PE: Many models use LOD_0... to indentify LOD levels.
|
||||
if (nodeName.Length() > 4 && nodeName[3] == '_')
|
||||
// Some models use LOD_0 to identify LOD levels
|
||||
if (nodeName.Length() > index + 4 && nodeName[index + 3] == '_')
|
||||
index++;
|
||||
|
||||
int32 num;
|
||||
if (!StringUtils::Parse(nodeName.Get() + index + 3, &num))
|
||||
{
|
||||
if (num >= 0 && num < MODEL_MAX_LODS)
|
||||
{
|
||||
return num;
|
||||
}
|
||||
|
||||
LOG(Warning, "Invalid mesh level of detail index at node \'{0}\'. Maximum supported amount of LODs is {1}.", nodeName, MODEL_MAX_LODS);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user