Reputation: 60
I am attempting to read an OBJ file with texture coordinates using the VCG library in C++. Here's the code snippet I am working with:
std::string DelaudeyMeshWithTexture =
"E:/Learn_MeshLab/meshlab/build/data/DelauneyWithTexture.obj";
CMeshO delaunayMesh;
int mask = vcg::tri::io::Mask::IOM_VERTTEXCOORD | vcg::tri::io::Mask::IOM_WEDGTEXCOORD;
int result = vcg::tri::io::ImporterOBJ<CMeshO>::Open(delaunayMesh, DelaudeyMeshWithTexture.c_str(), mask);
delaunayMesh.face.EnableWedgeTexCoord();
if (!(mask & vcg::tri::io::Mask::IOM_WEDGTEXCOORD)) {
std::cerr << "Warning: Delaunay mesh does not have wedge texture coordinates." << std::endl;
}
for (const auto& face : delaunayMesh.face) {
if (!face.IsD()) {
for (int j = 0; j < 3; ++j) {
const auto& texCoord = face.WT(j);
qDebug() << texCoord.U() << "," << texCoord.V();
}
}
}
However, when I run the code, I keep getting this warning:
Warning: Delaunay mesh does not have wedge texture coordinates.
And the output is always:
0.5 , 0.5
0.5 , 0.5
0.5 , 0.5
...ALL 0.5
I also tried setting the mask to 0
, but that didn't work either.
Why is VCG not reading the wedge texture coordinates correctly, and how can I fix this?
Upvotes: -2
Views: 72
Reputation: 60
I just solved this issue. I found that after adding this line, delaunayMesh.face.EnableWedgeTexCoord();
, and modifying the output format for the face texture coordinates as follows:
for (auto& face : delaunayMesh.face) {
for (int i = 0; i < 3; i++) {
// Get the texture coordinates of the current vertex
Point2f texCoord = face.WT(i).P();
qDebug()
<< "Vertex texture coordinates: " << texCoord.X() << ", " << texCoord.Y();
}
}
my coordinates started loading correctly. I still don’t fully understand the difference between face.WT(i).P()
and my original definition, but at least the issue is now resolved.
Upvotes: 1