Support PLY with texture coordinates parameters named (s, t)

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.

Paul Borke’s PLY web page is sometimes cited as the best doc available on the PLY format, but it doesn’t mention any particulars about texture coordinate naming conventions in PLY files. Blender appears to output “s” and “t” as the texture coordinate names according to an example in this Wikipedia article, so it seems reasonable to me for VTK to interpret those property names as texture coordinates.

What do you think @sankhesh @mwestphal ?

Sounds fair to me.

Sounds reasonable to me too, given that rst are common (similar to uvw) texture coordinate referring schemes in graphics APIs.

@afavray.modjaw would you be willing to submit a merge request that adds support for s and t coordinate parameters? See https://gitlab.kitware.com/vtk/vtk/-/blob/master/CONTRIBUTING.md?ref_type=heads for how to contribute. I’d be happy to assist you with the contribution workflow.

1 Like

I would be happy to contribute!

I’ll try to free up some time to do it in a few days.

1 Like

Please CC me on any MR, we use ply and could give it a test too.

The MR:

Support PLY with texture coordinates parameters named (s, t) (!12810) · Merge requests · VTK / VTK · GitLab