mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-17 20:52:36 +01:00
Updated meshoptimizer.
This commit is contained in:
22
3rdparty/meshoptimizer/src/simplifier.cpp
vendored
22
3rdparty/meshoptimizer/src/simplifier.cpp
vendored
@@ -252,7 +252,7 @@ static bool hasEdge(const EdgeAdjacency& adjacency, unsigned int a, unsigned int
|
||||
return false;
|
||||
}
|
||||
|
||||
static void classifyVertices(unsigned char* result, unsigned int* loop, unsigned int* loopback, size_t vertex_count, const EdgeAdjacency& adjacency, const unsigned int* remap, const unsigned int* wedge)
|
||||
static void classifyVertices(unsigned char* result, unsigned int* loop, unsigned int* loopback, size_t vertex_count, const EdgeAdjacency& adjacency, const unsigned int* remap, const unsigned int* wedge, unsigned int options)
|
||||
{
|
||||
memset(loop, -1, vertex_count * sizeof(unsigned int));
|
||||
memset(loopback, -1, vertex_count * sizeof(unsigned int));
|
||||
@@ -274,7 +274,15 @@ static void classifyVertices(unsigned char* result, unsigned int* loop, unsigned
|
||||
{
|
||||
unsigned int target = edges[j].next;
|
||||
|
||||
if (!hasEdge(adjacency, target, vertex))
|
||||
if (target == vertex)
|
||||
{
|
||||
// degenerate triangles have two distinct edges instead of three, and the self edge
|
||||
// is bi-directional by definition; this can break border/seam classification by "closing"
|
||||
// the open edge from another triangle and falsely marking the vertex as manifold
|
||||
// instead we mark the vertex as having >1 open edges which turns it into locked/complex
|
||||
openinc[vertex] = openout[vertex] = vertex;
|
||||
}
|
||||
else if (!hasEdge(adjacency, target, vertex))
|
||||
{
|
||||
openinc[target] = (openinc[target] == ~0u) ? vertex : target;
|
||||
openout[vertex] = (openout[vertex] == ~0u) ? target : vertex;
|
||||
@@ -354,6 +362,11 @@ static void classifyVertices(unsigned char* result, unsigned int* loop, unsigned
|
||||
}
|
||||
}
|
||||
|
||||
if (options & meshopt_SimplifyLockBorder)
|
||||
for (size_t i = 0; i < vertex_count; ++i)
|
||||
if (result[i] == Kind_Border)
|
||||
result[i] = Kind_Locked;
|
||||
|
||||
#if TRACE
|
||||
printf("locked: many open edges %d, disconnected seam %d, many seam edges %d, many wedges %d\n",
|
||||
int(stats[0]), int(stats[1]), int(stats[2]), int(stats[3]));
|
||||
@@ -1264,7 +1277,7 @@ MESHOPTIMIZER_API unsigned int* meshopt_simplifyDebugLoop = 0;
|
||||
MESHOPTIMIZER_API unsigned int* meshopt_simplifyDebugLoopBack = 0;
|
||||
#endif
|
||||
|
||||
size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions_data, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error, float* out_result_error)
|
||||
size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices, size_t index_count, const float* vertex_positions_data, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error, unsigned int options, float* out_result_error)
|
||||
{
|
||||
using namespace meshopt;
|
||||
|
||||
@@ -1272,6 +1285,7 @@ size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices,
|
||||
assert(vertex_positions_stride > 0 && vertex_positions_stride <= 256);
|
||||
assert(vertex_positions_stride % sizeof(float) == 0);
|
||||
assert(target_index_count <= index_count);
|
||||
assert((options & ~(meshopt_SimplifyLockBorder)) == 0);
|
||||
|
||||
meshopt_Allocator allocator;
|
||||
|
||||
@@ -1291,7 +1305,7 @@ size_t meshopt_simplify(unsigned int* destination, const unsigned int* indices,
|
||||
unsigned char* vertex_kind = allocator.allocate<unsigned char>(vertex_count);
|
||||
unsigned int* loop = allocator.allocate<unsigned int>(vertex_count);
|
||||
unsigned int* loopback = allocator.allocate<unsigned int>(vertex_count);
|
||||
classifyVertices(vertex_kind, loop, loopback, vertex_count, adjacency, remap, wedge);
|
||||
classifyVertices(vertex_kind, loop, loopback, vertex_count, adjacency, remap, wedge, options);
|
||||
|
||||
#if TRACE
|
||||
size_t unique_positions = 0;
|
||||
|
||||
Reference in New Issue
Block a user