Hello,
I am using vtkPLYReader to import various PLY meshes in my project (python VTK 9.5.2).
I have a problem with some PLY file formats that use external texture : the vtkPLYReader fails to parse texture coordinates on some of them. So I lost all information about texture and can’t display correctly the mesh color.
It seems VTK (9.5.2) currently only support texture coordinates expressed using properties named (u, v) or (texture_u, texture_v), and doesn’t support (s, t) which is also frequently used.
Is it possible to add support for these parameters name?
After checking the vtkPLYReader.cxx, it seems it’s doable by adapting a few lines:
int vtkPLYReader::RequestData(vtkInformation* vtkNotUsed(request),
vtkInformationVector** vtkNotUsed(inputVector), vtkInformationVector* outputVector)
{
...
bool texCoordsPointsAvailable = false;
vtkSmartPointer<vtkFloatArray> texCoordsPoints = nullptr;
if ((elem = vtkPLY::find_element(ply, "vertex")) != nullptr)
{
if (vtkPLY::find_property(elem, "u", &index) != nullptr &&
vtkPLY::find_property(elem, "v", &index) != nullptr)
{
texCoordsPointsAvailable = true;
}
else if (vtkPLY::find_property(elem, "texture_u", &index) != nullptr &&
vtkPLY::find_property(elem, "texture_v", &index) != nullptr)
{
texCoordsPointsAvailable = true;
vertProps[3].name = "texture_u";
vertProps[4].name = "texture_v";
}
else if (vtkPLY::find_property(elem, "s", &index) != nullptr &&
vtkPLY::find_property(elem, "t", &index) != nullptr)
{
texCoordsPointsAvailable = true;
vertProps[3].name = "s";
vertProps[4].name = "t";
}
if (texCoordsPointsAvailable)
{
texCoordsPoints = vtkSmartPointer<vtkFloatArray>::New();
texCoordsPoints->SetName("TCoords");
texCoordsPoints->SetNumberOfComponents(2);
output->GetPointData()->SetTCoords(texCoordsPoints);
}
}
...
}
Please correct me if I’m wrong.