Commit c1d6c34f authored by Uwe Schulzweida's avatar Uwe Schulzweida
Browse files

subdivide: Allocate triangleList in advanced.

parent d00a66d1
...@@ -82,18 +82,21 @@ static TriangleList ...@@ -82,18 +82,21 @@ static TriangleList
subdivide(VertexList &vertices, TriangleList triangles) subdivide(VertexList &vertices, TriangleList triangles)
{ {
Lookup lookup; Lookup lookup;
TriangleList result;
Triangle mid; Triangle mid;
for (const auto &each : triangles) size_t n = triangles.size();
TriangleList result(4*n);
for (size_t i = 0; i < n; ++i)
{ {
const auto &each = triangles[i];
for (int edge = 0; edge < 3; ++edge) for (int edge = 0; edge < 3; ++edge)
mid[edge] = vertexForEdge(lookup, vertices, each[edge], each[(edge + 1) % 3]); mid[edge] = vertexForEdge(lookup, vertices, each[edge], each[(edge + 1) % 3]);
result.push_back({{ each[0], mid[0], mid[2] }}); result[i*4+0] = {{ each[0], mid[0], mid[2] }};
result.push_back({{ each[1], mid[1], mid[0] }}); result[i*4+1] = {{ each[1], mid[1], mid[0] }};
result.push_back({{ each[2], mid[2], mid[1] }}); result[i*4+2] = {{ each[2], mid[2], mid[1] }};
result.push_back(mid); result[i*4+3] = mid;
} }
return result; return result;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment