2
$\begingroup$

For some time I have been working on UV unwrapper for radiosity computation. The information online about it is very sparse, except how to do it in some high end software. So far I have used triplanar method. The mesh I am testing is Sponza obj file - which consist of 384 objects in single file.

This method computes normal of each triangle and depending on its direction take into consideration two components of position of model in world space.

glm::vec3 faceNormal = glm::normalize( glm::cross( v1-v0, v2-v0 ) );
float NdotXAxis = std::abs( faceNormal.x );
float NdotYAxis = std::abs( faceNormal.y );
float NdotZAxis = std::abs( faceNormal.z );

if (NdotXAxis > NdotYAxis && NdotXAxis > NdotZAxis)
{
    Triangle t;
    t.v[0] = {v0.z, v0.y};
    t.v[1] = {v1.z, v1.y};
    t.v[2] = {v2.z, v2.y};
    clustersX[i].triangles.push_back(t);

}
else if (NdotYAxis > NdotXAxis && NdotYAxis > NdotZAxis)
{
    Triangle t;
    t.v[0] = {v0.x, v0.z};
    t.v[1] = {v1.x, v1.z};
    t.v[2] = {v2.x, v2.z};
    clustersY[i].triangles.push_back(t);
}
else
{
    Triangle t;
    t.v[0] = {v0.x, v0.y};
    t.v[1] = {v1.x, v1.y};
    t.v[2] = {v2.x, v2.y};
    clustersZ[i].triangles.push_back(t);
}

Each object has three clusters of triangles in each axis. These clusters have bounding rectangle positions. Then they are packed into single image using recursive rectangle packing algorithm and normalized to $[0, 1]$ range.

But this creates problems, which exist among triangles in single cluster - if these triangles have, for example, major $x$ axis component and similar $z$ and $y$ positions, they will overlap in final texture.

I tried to detect this and then pack overalapping triangles to different clusters and it works but it is tedious (check every triangle with every other triangle in each cluster) and not very efficient in further packing process. So is there other better method for UV unwrapping or more elegant solution for correction in this method?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.