simplify qhull to hull conversion

This commit is contained in:
Irlan 2018-04-29 22:35:40 -03:00
parent c9f0b0cf93
commit f3c263111b

View File

@ -31,6 +31,13 @@ struct b3UniqueArray
count = 0; count = 0;
} }
// Add the value if not found
void Add(const T& value)
{
B3_ASSERT(count < N);
values[count++] = value;
}
// Add the value if not found // Add the value if not found
// Return value index if added // Return value index if added
// Return N if the array is full // Return N if the array is full
@ -178,22 +185,37 @@ void b3QHull::Set(const b3Vec3* points, u32 count)
qhHull hull; qhHull hull;
hull.Construct(qhBuffer, ps, psCount); hull.Construct(qhBuffer, ps, psCount);
// Convert the constructed hull into a run-time hull. if (hull.GetVertexList().count > B3_MAX_HULL_VERTICES)
b3UniqueArray<qhVertex*, B3_MAX_HULL_VERTICES> vs;
b3UniqueArray<qhHalfEdge*, B3_MAX_HULL_EDGES> es;
u32 fs_count = 0;
// Add vertices and edges to the map
for (qhFace* face = hull.GetFaceList().head; face != NULL; face = face->next)
{ {
// Add face // Vertex excess
if (fs_count == B3_MAX_HULL_FACES) b3Free(qhBuffer);
return;
}
if (hull.GetFaceList().count > B3_MAX_HULL_FACES)
{ {
// Face excess // Face excess
b3Free(qhBuffer); b3Free(qhBuffer);
return; return;
} }
// Convert the constructed hull into a run-time hull.
b3UniqueArray<qhVertex*, B3_MAX_HULL_VERTICES> vs;
b3UniqueArray<qhHalfEdge*, B3_MAX_HULL_EDGES> es;
u32 fs_count = 0;
// Add vertices to the map
for (qhVertex* vertex = hull.GetVertexList().head; vertex != NULL; vertex = vertex->next)
{
// Add vertex
vs.Add(vertex);
}
// Add faces and to the map
for (qhFace* face = hull.GetFaceList().head; face != NULL; face = face->next)
{
// Add face
B3_ASSERT(fs_count < B3_MAX_HULL_FACES);
++fs_count; ++fs_count;
// Add vertices and half-edges // Add vertices and half-edges
@ -201,15 +223,6 @@ void b3QHull::Set(const b3Vec3* points, u32 count)
qhHalfEdge* edge = begin; qhHalfEdge* edge = begin;
do do
{ {
// Add vertex
u32 iv = vs.Find(edge->tail);
if (iv == B3_MAX_HULL_VERTICES)
{
// Vertex excess
b3Free(qhBuffer);
return;
}
// Add half-edge // Add half-edge
u32 iedge = es.Find(edge); u32 iedge = es.Find(edge);
if (iedge == B3_MAX_HULL_EDGES) if (iedge == B3_MAX_HULL_EDGES)