|
|
|
@ -25,10 +25,14 @@ |
|
|
|
#include "Icosphere.h" |
|
|
|
#include "Icosphere.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "Math/Vector3.h" |
|
|
|
#include "Math/Vector3.h" |
|
|
|
|
|
|
|
#include "Trade/MeshData3D.h" |
|
|
|
|
|
|
|
#include "MeshTools/Subdivide.h" |
|
|
|
|
|
|
|
#include "MeshTools/RemoveDuplicates.h" |
|
|
|
|
|
|
|
|
|
|
|
namespace Magnum { namespace Primitives { |
|
|
|
namespace Magnum { namespace Primitives { |
|
|
|
|
|
|
|
|
|
|
|
Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, { |
|
|
|
Trade::MeshData3D Icosphere::solid(const UnsignedInt subdivisions) { |
|
|
|
|
|
|
|
std::vector<UnsignedInt> indices{ |
|
|
|
1, 2, 6, |
|
|
|
1, 2, 6, |
|
|
|
1, 7, 2, |
|
|
|
1, 7, 2, |
|
|
|
3, 4, 5, |
|
|
|
3, 4, 5, |
|
|
|
@ -49,7 +53,9 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, { |
|
|
|
7, 1, 0, |
|
|
|
7, 1, 0, |
|
|
|
3, 9, 8, |
|
|
|
3, 9, 8, |
|
|
|
4, 8, 0 |
|
|
|
4, 8, 0 |
|
|
|
}, {}, {{ |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Vector3> vertices{ |
|
|
|
{0.0f, -0.525731f, 0.850651f}, |
|
|
|
{0.0f, -0.525731f, 0.850651f}, |
|
|
|
{0.850651f, 0.0f, 0.525731f}, |
|
|
|
{0.850651f, 0.0f, 0.525731f}, |
|
|
|
{0.850651f, 0.0f, -0.525731f}, |
|
|
|
{0.850651f, 0.0f, -0.525731f}, |
|
|
|
@ -62,8 +68,15 @@ Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, { |
|
|
|
{0.0f, -0.525731f, -0.850651f}, |
|
|
|
{0.0f, -0.525731f, -0.850651f}, |
|
|
|
{0.0f, 0.525731f, -0.850651f}, |
|
|
|
{0.0f, 0.525731f, -0.850651f}, |
|
|
|
{0.0f, 0.525731f, 0.850651f} |
|
|
|
{0.0f, 0.525731f, 0.850651f} |
|
|
|
}}, {}) { |
|
|
|
}; |
|
|
|
positions(0).assign(normals(0).begin(), normals(0).end()); |
|
|
|
|
|
|
|
|
|
|
|
for(std::size_t i = 0; i != subdivisions; ++i) |
|
|
|
|
|
|
|
MeshTools::subdivide(indices, vertices, [](const Vector3& a, const Vector3& b) { |
|
|
|
|
|
|
|
return (a+b).normalized(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MeshTools::removeDuplicates(indices, vertices); |
|
|
|
|
|
|
|
return Trade::MeshData3D(Mesh::Primitive::Triangles, std::move(indices), {vertices}, {std::move(vertices)}, {}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}} |
|
|
|
}} |
|
|
|
|