msh
msh copied to clipboard
msh_ply: Is it possible to define color per vertex ?
Hello,
So far I have used msh_ply
to write a PLY file containing XYZ vertices and faces.
I would like to support color per vertex, is this possible ?
The PLY header would be:
ply
format binary_little_endian 1.0
element vertex 6612
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
element face 6392
property list uchar int vertex_indices
end_header
...
How would you define the corresponding "vertex" descriptor ?
Thanks for your help!
Oh my, I have completely missed this! It's a year late, but if someone else has similar issue - msh_ply can support arbitrary descriptors like so:
msh_ply_t *pf = msh_ply_open( filename, "wb" );
int32_t error = MSH_PLY_FILE_OPEN_ERR;
if( pf )
{
error = MSH_PLY_NO_ERR;
const char* vertex_attributes[] = { "x", "y", "z",
"nx", "ny", "nz",
"red", "green", "blue" };
const char* face_attributes[] = { "vertex_indices" };
msh_ply_desc_t positions_desc = { (char*)"vertex", &vertex_attributes[0], 3, MSH_PLY_FLOAT, MSH_PLY_INVALID,
&vertex_positions, NULL, &vertex_count, 0 };
msh_ply_desc_t normals_desc = { (char*)"vertex", &vertex_attributes[3], 3, MSH_PLY_FLOAT, MSH_PLY_INVALID,
&vertex_normals, NULL, &vertex_count, 0 };
msh_ply_desc_t colors_desc = { (char*)"vertex", &vertex_attributes[6], 3, MSH_PLY_UINT8, MSH_PLY_INVALID,
&vertex_colors, NULL, &vertex_count, 0 };
msh_ply_desc_t face_desc = { (char*)"face", &face_attributes[0], 1, MSH_PLY_INT32, MSH_PLY_UINT8,
&faces_ind, NULL, &face_count, 3 };
msh_ply_add_descriptor( pf, &positions_desc );
msh_ply_add_descriptor( pf, &normals_desc );
msh_ply_add_descriptor( pf, &colors_desc );
error = msh_ply_write(pf);
if ( error) printf("%s\n", msh_ply_error_msg( error ) );
}
msh_ply_close(pf);