Updated tests, changed model encoders to output content to a stream
This commit is contained in:
@@ -11,56 +11,9 @@
|
||||
|
||||
namespace OpenVulkano::Scene
|
||||
{
|
||||
std::string GetUsdContents(OpenVulkano::Scene::Geometry* geometry, const std::string texturePath = "")
|
||||
void WriteUsdContents(std::ostream& output, OpenVulkano::Scene::Geometry* geometry)
|
||||
{
|
||||
std::ostringstream result;
|
||||
std::ostringstream points, normals, indices, texCoords, faceCounts;
|
||||
points << std::fixed << std::setprecision(6);
|
||||
normals << std::fixed << std::setprecision(6);
|
||||
|
||||
for (size_t i = 0; i < geometry->vertexCount; ++i)
|
||||
{
|
||||
const auto& v = geometry->vertices[i];
|
||||
points << "(" << v.position.x << ", " << v.position.y << ", " << v.position.z << ")";
|
||||
normals << "(" << v.normal.x << ", " << v.normal.y << ", " << v.normal.z << ")";
|
||||
if (i < geometry->vertexCount - 1)
|
||||
{
|
||||
points << ", ";
|
||||
normals << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < geometry->indexCount; ++i)
|
||||
{
|
||||
indices << geometry->GetIndex(i);
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
indices << ", ";
|
||||
}
|
||||
if ((i + 1) % 3 == 0)
|
||||
{
|
||||
faceCounts << "3";
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
faceCounts << ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
texCoords << std::fixed << std::setprecision(6);
|
||||
|
||||
for (size_t i = 0; i < geometry->indexCount; ++i)
|
||||
{
|
||||
const size_t vertexIndex = geometry->GetIndex(i);
|
||||
const auto& v = geometry->vertices[vertexIndex];
|
||||
texCoords << "(" << v.textureCoordinates.x << ", " << v.textureCoordinates.y << ")";
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
texCoords << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
result << R"(#usda 1.0
|
||||
output << R"(#usda 1.0
|
||||
(
|
||||
defaultPrim = "root"
|
||||
doc = "Exported from OpenVulkano"
|
||||
@@ -91,19 +44,79 @@ def Xform "root" (
|
||||
{
|
||||
uniform bool doubleSided = 1
|
||||
float3[] extent = [(-0.5, -0.5, 0), (0.5, 0.5, 0)]
|
||||
int[] faceVertexCounts = [)"
|
||||
<< faceCounts.str() << R"(]
|
||||
int[] faceVertexIndices = [)"
|
||||
<< indices.str() << R"(]
|
||||
int[] faceVertexCounts = [)";
|
||||
|
||||
for (size_t i = 0; i < geometry->indexCount; ++i)
|
||||
{
|
||||
if ((i + 1) % 3 == 0)
|
||||
{
|
||||
output << "3";
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
output << ", ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
output << R"(]
|
||||
int[] faceVertexIndices = [)";
|
||||
|
||||
for (size_t i = 0; i < geometry->indexCount; ++i)
|
||||
{
|
||||
output << geometry->GetIndex(i);
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
output << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
output << R"(]
|
||||
rel material:binding = </root/_materials/Material0>
|
||||
normal3f[] normals = [)"
|
||||
<< normals.str() << R"(] (
|
||||
normal3f[] normals = [)";
|
||||
|
||||
output << std::fixed << std::setprecision(6);
|
||||
for (size_t i = 0; i < geometry->vertexCount; ++i)
|
||||
{
|
||||
const auto& v = geometry->vertices[i];
|
||||
output << "(" << v.normal.x << ", " << v.normal.y << ", " << v.normal.z << ")";
|
||||
if (i < geometry->vertexCount - 1)
|
||||
{
|
||||
output << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
output << R"(] (
|
||||
interpolation = "faceVarying"
|
||||
)
|
||||
point3f[] points = [)"
|
||||
<< points.str() << R"(]
|
||||
texCoord2f[] primvars:st = [)"
|
||||
<< texCoords.str() << R"(] (
|
||||
point3f[] points = [)";
|
||||
|
||||
for (size_t i = 0; i < geometry->vertexCount; ++i)
|
||||
{
|
||||
const auto& v = geometry->vertices[i];
|
||||
output << "(" << v.position.x << ", " << v.position.y << ", " << v.position.z << ")";
|
||||
if (i < geometry->vertexCount - 1)
|
||||
{
|
||||
output << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
output << R"(]
|
||||
texCoord2f[] primvars:st = [)";
|
||||
|
||||
output << std::fixed << std::setprecision(6);
|
||||
|
||||
for (size_t i = 0; i < geometry->indexCount; ++i)
|
||||
{
|
||||
const size_t vertexIndex = geometry->GetIndex(i);
|
||||
const auto& v = geometry->vertices[vertexIndex];
|
||||
output << "(" << v.textureCoordinates.x << ", " << v.textureCoordinates.y << ")";
|
||||
if (i < geometry->indexCount - 1)
|
||||
{
|
||||
output << ", ";
|
||||
}
|
||||
}
|
||||
|
||||
output << R"(] (
|
||||
interpolation = "faceVarying"
|
||||
)
|
||||
uniform token subdivisionScheme = "none"
|
||||
@@ -153,6 +166,5 @@ def Xform "root" (
|
||||
}
|
||||
}
|
||||
)";
|
||||
return result.str();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user