Fast-Quadric-Mesh-Simplification icon indicating copy to clipboard operation
Fast-Quadric-Mesh-Simplification copied to clipboard

Mesh simplification using a custom vertex buffer

Open Zeta48 opened this issue 2 years ago • 5 comments

I am looking for a mesh simplification library to add LOD system to my engine. I found your api pretty cool and I would like to use it. To do so mesh vertices should includes more attributes than just the position. In my case it would turn to this in Simplify.h:

`

struct VertexData  
{  
	vec3f position;  
	vec3f normal;
	vec3f tangent;
	vec3f bitangent;
	vec3f texCoord;
};
struct Vertex { VertexData p;int tstart,tcount;SymetricMatrix q;int border;};

` Instead of just this:

struct Vertex { vec3f p;int tstart,tcount;SymetricMatrix q;int border;};

With my new definition i got compilation errors that I don't know how to remove properly.
So I think it could be a good idea to generalize the Vertex. Something like this would be cool:

`

// The vertex data. Must at least contain the position.
struct VertexData
{
	static const unsigned int s_NbFloats = 3;
	static_assert(s_NbFloats >= 3, "Nb float must be at least 3");
	std::array<float, s_NbFloats> vData;
};
struct Vertex { VertexData vd;int tstart,tcount;SymetricMatrix q;int border;};

`

Hoping it is feasible,

Thanks for helping!

Zeta48 avatar Nov 16 '22 04:11 Zeta48

@Zeta48 it is easy to calculate normals for a triangulated mesh. For sample Python code see here and for Pascal code see here. Just make sure you pay attention to triangle winding, which differentiates the front and back face.

Likewise, here is sample C code for deriving the mesh tangent. Blender uses the MikkTSpace algorithm which is described with C source here.

Recent versions of this project should interpolate texCoords, so just make sure they are specified in your input mesh.

My sense is that you could simplify the mesh with the existing code and write additional code to derive the normals, tangents and bittangents from the resulting simplified mesh and UV map.

neurolabusc avatar Nov 16 '22 12:11 neurolabusc

Oh yes the UVs are present in src.cmd/Simplify.h. There is two Simplify.h. What is the difference between src.gl/Simplify.h and src.cmd/Simplify.h?

Zeta48 avatar Nov 16 '22 18:11 Zeta48

src.cmd is for a command line program and src.gl is for a graphical user interface. Historically, I think the Simplify.h files were identical for each project. However, the command line tool was extended to support texture mapping while this was not supported in the graphical tool. If you do update the graphical program to support these new features, feel free to submit a pull request.

neurolabusc avatar Nov 16 '22 19:11 neurolabusc

I understand thank you :)

Zeta48 avatar Nov 16 '22 20:11 Zeta48

Texture coordinates are stored per triangle instead of per vertex. Is there a good reason for this? @timknip

Zeta48 avatar Nov 16 '22 20:11 Zeta48

Closing this issue. UV textures are supported. Feel free to provide a PR if you want to extend them. While I agree that it seems like these properties intuitively feel per vertex rather than with the triangles, the current implementation works efficiently.

neurolabusc avatar Jul 18 '24 20:07 neurolabusc