sp4cerat / Fast-Quadric-Mesh-Simplification

Mesh triangle reduction using quadrics
MIT License
1.5k stars 239 forks source link

vertex color #5

Closed chukcha2 closed 2 years ago

chukcha2 commented 7 years ago

Hello, Some applications (like meshlab) append rgb values to vertex lines. From wikipedia:

Some applications support vertex colors, by putting red, green and blue values after x y and z. The color values range from 0 to 1

When I tried the tool with obj file with vertex color, the output obj lost the color. Would it be possible to enhance the tool to keep vertex color?

Lin20 commented 6 years ago

I used this project for my meshes that have color information supplied in the vertices. All you have to do is add a Vec3 after the position and average the two vertex colors when collapsing an edge. There's also a function called compact_mesh that copies vertices, so you have to make it copy the color info too. You really only end up adding like 4 lines to the code and the simplification retains all color info perfectly.

neurolabusc commented 2 years ago

@Lin20 your solution is a good one. Since this message was posted, the repository has been updated to track OBJ format texture coordinates. The TEXCOORD attribute could provides a template for how to handle per-vertex colors. In other words, the TEXCOORDs intepolate across a 2D texture (u,v), while for vertex colors you will want to interpolate the Red, Green and Blue components (r,g,b).