After reading a paper and watchind some videos about nanite I decided to try (Doing my best…) to implement an hierarchical LODs rendering using mesh shaders. I’m using Zeux’s library Meshoptmizer(GitHub - zeux/meshoptimizer: Mesh optimization library that makes meshes smaller and faster to render) to help me achieve that. The library defines a meshlet as a couple of indexes and counts.
struct meshopt_Meshlet
{
/* offsets within meshlet_vertices and meshlet_triangles arrays with meshlet data */
unsigned int vertex_offset;
unsigned int triangle_offset;
/* number of vertices and triangles used in the meshlet; data is stored in consecutive range defined by offset and count */
unsigned int vertex_count;
unsigned int triangle_count;
};
The function meshopt_buildMeshlets outputs an array of meshopt_meshlet 's and the buffers that each meshopt_meshlet indexes into (meshlet_triangles and meshlet_vertices). I would like to know, given this structure, how would I merge two meshletsand then use the method meshopt_simplify to simplify their geometry. All this indexing process is quite complicated for me, I’m trying to think in a way that makes sense and works for me.
Cluster father;
Cluster children1 = active_clusters[neighbor_of_i];
Cluster children2 = active_clusters[i];
father.meshlet.triangle_offset = min(children1.meshlet.triangle_offset,children2.meshlet.triangle_offset);
father.meshlet.vertex_offset = min(children1.meshlet.vertex_offset,children2.meshlet.vertex_offset);
father.meshlet.vertex_count = children1.meshlet.vertex_count + children2.meshlet.vertex_count;
father.meshlet.triangle_count = children1.meshlet.triangle_count + children2.meshlet.triangle_count;
father.aabb = compute_cluster_aabb(vertices,father.meshlet);//Compute AABB
Consider that Cluster has a meshopt_meshlet field.
Could anyone demonstrate to me how do Merge two meshopt_meshlets and simplify their geomtry using meshopt_simplify, I’m not sure about how to properly index the the final vertex/index buffer. This question may be a bit hard for me to properly explain myself, so please let me know what details you need.