Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PLY file specifications with texture coordinates

I need to read PLY files (Stanford Triangle Format) with embedded texture for some purpose. I saw several specification of PLY files, but could not find a single source specifying the syntax for texture mapping. There seems to be so many libraries which reads PLY file, but most of them seems not to support texture (they just crashes; I tried 2-3 of them). Following is in the header for a ply file with texture:

ply
format binary_little_endian 1.0
comment TextureFile Parameterization.png
element vertex 50383               
property float x
property float y
property float z
property float nx
property float ny
property float nz
element face 99994               
property list uint8 int32 vertex_index
property list uint8 float texcoord
end_header

What I don't understand is the line property list uint8 float texcoord. Also the list corresponding to a face is

3 1247 1257 1279 6 0.09163 0.565323 0.109197 0.565733 0.10888 0.602539 6 9 0.992157 0.992157 0.992157 0.992157 0.992157 0.992157 0.992157 0.992157 0.992157`. 

What is this list; what is the format? While I understand that PLY gives you the opportunity to define your own properties for the elements, but the handling textures seems to be pretty much a standard and quite a few applications (like the popular Meshlab) seems to open textured PLY files using the above syntax.

I want to know what is the standard syntax followed for reading textured PLY files and if possible the source from where this information is found.

like image 875
krips89 Avatar asked Feb 11 '15 15:02

krips89


1 Answers

In PLY files faces often contain lists of values and these lists can vary in size. If it's a triangular face, expect three values, a quad = 4 and so on up to any arbitrary n-gon. A list is declared in a line like this:

property list uint8 int32 vertex_index

This is a list called 'vertex_index'. It will always consist of an 8-bit unsigned integer (that's the uint8) that is the size N, followed by N 32-bit integers (that's the int32).

In the example line this shows up right away:

3 1247 1257 1279

This says, here comes 3 values and then it gives you the three.

Now the second list is where the texture coordinates should be:

property list uint8 float texcoord

It's just like the first list in that the size comes first (as an unsigned byte) but this time it will be followed by a series of 32-bit floats instead of integers (makes sense for texture coordinates). The straightforward interpretation is that there will be a texture coordinate for each of the vertices listed in vertex_index. If we assume these are just 2d texture coordinates (a pretty safe assumption) we should expect to see the number 6 followed by 6 floating point values ... and we do:

6 0.09163 0.565323 0.109197 0.565733 0.10888 0.602539

These are the texture coordinates that correspond with the three vertices already listed.

Now, for a face, that should be it. I don't know what the stuff is on the rest of the line. According to your header the rest of the file should be binary so I don't know how you got it as a line of ascii text but the extra data on that line shouldn't be there (also according to the header which fully defines a face).

like image 151
OllieBrown Avatar answered Nov 03 '22 01:11

OllieBrown