Import material textures with mesh assets

This commit is contained in:
2026-03-26 16:22:24 +08:00
parent c479595bf5
commit e174862b8a
18 changed files with 622 additions and 21 deletions

View File

@@ -1,6 +1,8 @@
#include <gtest/gtest.h>
#include <XCEngine/Resources/Mesh/MeshLoader.h>
#include <XCEngine/Resources/Mesh/MeshImportSettings.h>
#include <XCEngine/Resources/Material/Material.h>
#include <XCEngine/Resources/Texture/Texture.h>
#include <XCEngine/Core/Asset/ResourceTypes.h>
#include <XCEngine/Core/Containers/Array.h>
#include <filesystem>
@@ -102,4 +104,32 @@ TEST(MeshLoader, GeneratesNormalsAndTangentsWhenRequested) {
delete mesh;
}
TEST(MeshLoader, ImportsMaterialTexturesFromObj) {
MeshLoader loader;
const std::string path = GetMeshFixturePath("textured_triangle.obj");
LoadResult result = loader.Load(path.c_str());
ASSERT_TRUE(result);
ASSERT_NE(result.resource, nullptr);
auto* mesh = static_cast<Mesh*>(result.resource);
ASSERT_EQ(mesh->GetSections().Size(), 1u);
ASSERT_GE(mesh->GetMaterials().Size(), 1u);
EXPECT_LT(mesh->GetSections()[0].materialID, mesh->GetMaterials().Size());
Material* material = mesh->GetMaterial(mesh->GetSections()[0].materialID);
ASSERT_NE(material, nullptr);
EXPECT_TRUE(material->HasProperty("baseColorTexture"));
EXPECT_EQ(material->GetTextureBindingCount(), 1u);
ResourceHandle<Texture> diffuseTexture = material->GetTexture("baseColorTexture");
ASSERT_TRUE(diffuseTexture.IsValid());
EXPECT_EQ(diffuseTexture->GetWidth(), 2u);
EXPECT_EQ(diffuseTexture->GetHeight(), 2u);
EXPECT_EQ(diffuseTexture->GetPixelDataSize(), 16u);
EXPECT_EQ(mesh->GetTextures().Size(), 1u);
delete mesh;
}
} // namespace