Updated tests, changed model encoders to output content to a stream

This commit is contained in:
Vladyslav Baranovskyi
2024-11-25 19:34:05 +02:00
parent 7ede43d1c2
commit ba8574f537
4 changed files with 113 additions and 110 deletions

View File

@@ -14,30 +14,22 @@
namespace OpenVulkano::Scene
{
// Returns [objContents, mtlContents]
std::pair<std::string, std::string> GetObjContents(Geometry* geometry, const std::string& texturePath)
void WriteObjContents(Geometry* geometry, const std::string& texturePath, std::ostream& objContent, std::ostream& mtlContent)
{
std::pair<std::string, std::string> result;
bool useTexture = texturePath.size() != 0;
std::stringstream objContent;
objContent << "# OBJ file generated by OpenVulkanoCpp\n";
if (useTexture)
{
std::stringstream mtlContent;
std::string materialName = "Material0";
mtlContent << "newmtl " << materialName << R"(
mtlContent << R"(newmtl Material0
Ka 1.000 1.000 1.000
Kd 1.000 1.000 1.000
Ks 0.000 0.000 0.000
map_Ka texture.png
map_Kd texture.png
)";
objContent << "mtllib material.mtl\nusemtl " << materialName << "\n";
result.second = mtlContent.str();
objContent << "mtllib material.mtl\nusemtl Material0\n";
}
for (int i = 0; i < geometry->vertexCount; ++i)
@@ -62,9 +54,5 @@ map_Kd texture.png
uint32_t i2 = geometry->GetIndex(i + 2) + 1;
objContent << fmt::format("f {0}/{0}/{0} {1}/{1}/{1} {2}/{2}/{2}\n", i0, i1, i2);
}
result.first = objContent.str();
return result;
}
}