The second simplification algorithm,
meshopt_simplifySloppy
, doesn't follow the topology of the original mesh. This means that it doesn't preserve attribute seams or borders, but it can collapse internal details that are too small to matter better because it can merge mesh features that are topologically disjoint but spatially close.
第二个简化算法meshopt_simplifySloppy
,它没有遵循原始网格的拓扑结构。这意味着它不保留属性接缝或边界,但是它可以折叠内部细节,因为它可以合并网格特征,这些特征在拓扑上是不相交的,但是在空间上非常接近。
float threshold = 0.2f;
size_t target_index_count = size_t(index_count * threshold);
float target_error = 1e-1f;
std::vector<unsigned int> lod(index_count);
float lod_error = 0.f;
lod.resize(meshopt_simplifySloppy(&lod[0], indices, index_count, &vertices[0].x, vertex_count, sizeof(Vertex),
target_index_count, target_error, &lod_error));
This algorithm will not stop early due to topology restrictions but can still do so if target index count can't be reached without introducing an error larger than target. It is 5-6x faster than
meshopt_simplify
when simplification ratio is large, and is able to reach ~20M triangles/sec on a desktop CPU (meshopt_simplify
works at ~3M triangles/sec).
该算法不会因为拓扑结构的限制而提前停止,但如果不能在不引入大于目标的误差的情况下达到目标索引计数,则仍然可以停止。当简化比率很大时,它比meshopt_simplify
快5-6倍,并且能够在桌面 CPU 上达到 ~ 20M 三角形/秒(meshopt_simplify
工作于 ~ 3M 三角形/秒)。
When a sequence of LOD meshes is generated that all use the original vertex buffer, care must be taken to order vertices optimally to not penalize mobile GPU architectures that are only capable of transforming a sequential vertex buffer range. It's recommended in this case to first optimize each LOD for vertex cache, then assemble all LODs in one large index buffer starting from the coarsest LOD (the one with fewest triangles), and call
meshopt_optimizeVertexFetch
on the final large index buffer. This will make sure that coarser LODs require a smaller vertex range and are efficient wrt vertex fetch and transform.
当生成的 LOD 网格序列都使用原始的顶点缓冲区时,必须注意最佳排序顶点,以避免惩罚只能转换顺序顶点缓冲区范围的移动 GPU 架构。在这种情况下,建议首先优化顶点缓存的每个 LOD,然后从最粗的 LOD (三角形最少的那个)开始,将所有 LOD 组装到一个大型索引缓冲区中,并在最终的大型索引缓冲区中调用meshopt_optimizeVertexFetch
。这将确保较粗的 LOD 需要较小的顶点范围,并且是有效的 wrt 顶点获取和转换。
Both algorithms can also return the resulting normalized deviation that can be used to choose the correct level of detail based on screen size or solid angle; the error can be converted to world space by multiplying by the scaling factor returned by
meshopt_simplifyScale
.
这两种算法还可以返回得到的归一化偏差,这些偏差可以用来根据屏幕大小或立体角度选择正确的细节级别; 这些误差可以通过乘以meshopt_simplifyScale
返回的比例因子转换为世界空间。