diff --git a/src/Primitives/Icosphere.cpp b/src/Primitives/Icosphere.cpp index 56a10f776..b6f09d32c 100644 --- a/src/Primitives/Icosphere.cpp +++ b/src/Primitives/Icosphere.cpp @@ -25,45 +25,58 @@ #include "Icosphere.h" #include "Math/Vector3.h" +#include "Trade/MeshData3D.h" +#include "MeshTools/Subdivide.h" +#include "MeshTools/RemoveDuplicates.h" namespace Magnum { namespace Primitives { -Icosphere<0>::Icosphere(): MeshData3D(Mesh::Primitive::Triangles, { - 1, 2, 6, - 1, 7, 2, - 3, 4, 5, - 4, 3, 8, - 6, 5, 11, - 5, 6, 10, - 9, 10, 2, - 10, 9, 3, - 7, 8, 9, - 8, 7, 0, - 11, 0, 1, - 0, 11, 4, - 6, 2, 10, - 1, 6, 11, - 3, 5, 10, - 5, 4, 11, - 2, 7, 9, - 7, 1, 0, - 3, 9, 8, - 4, 8, 0 -}, {}, {{ - {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}, - {-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.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()); +Trade::MeshData3D Icosphere::solid(const UnsignedInt subdivisions) { + std::vector indices{ + 1, 2, 6, + 1, 7, 2, + 3, 4, 5, + 4, 3, 8, + 6, 5, 11, + 5, 6, 10, + 9, 10, 2, + 10, 9, 3, + 7, 8, 9, + 8, 7, 0, + 11, 0, 1, + 0, 11, 4, + 6, 2, 10, + 1, 6, 11, + 3, 5, 10, + 5, 4, 11, + 2, 7, 9, + 7, 1, 0, + 3, 9, 8, + 4, 8, 0 + }; + + std::vector vertices{ + {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}, + {-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.0f, -0.525731f, -0.850651f}, + {0.0f, 0.525731f, -0.850651f}, + {0.0f, 0.525731f, 0.850651f} + }; + + 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)}, {}); } }} diff --git a/src/Primitives/Icosphere.h b/src/Primitives/Icosphere.h index 220db6bfe..e0a39360f 100644 --- a/src/Primitives/Icosphere.h +++ b/src/Primitives/Icosphere.h @@ -28,53 +28,26 @@ * @brief Class Magnum::Primitives::Icosphere */ -#include "Math/Vector3.h" -#include "MeshTools/RemoveDuplicates.h" -#include "MeshTools/Subdivide.h" -#include "Trade/MeshData3D.h" +#include "Trade/Trade.h" #include "Primitives/magnumPrimitivesVisibility.h" namespace Magnum { namespace Primitives { -/** @todoc Remove `ifndef` when Doxygen is sane again */ -#ifndef DOXYGEN_GENERATING_OUTPUT -template class MAGNUM_PRIMITIVES_EXPORT Icosphere; -#endif - -/** -@brief 3D icosphere primitive with zero subdivisions - -Indexed @ref Mesh::Primitive "Triangles" with normals. -*/ -template<> class Icosphere<0>: public Trade::MeshData3D { - public: - /** @brief Constructor */ - explicit Icosphere(); -}; - /** @brief 3D icosphere primitive -@tparam subdivisions Number of subdivisions -Indexed @ref Mesh::Primitive "Triangles" with normals. +Sphere with radius `1`. */ -#ifndef DOXYGEN_GENERATING_OUTPUT -template class Icosphere: public Icosphere<0> { -#else -template class Icosphere { -#endif +class MAGNUM_PRIMITIVES_EXPORT Icosphere { public: - /** @brief Constructor */ - explicit Icosphere() { - for(std::size_t i = 0; i != subdivisions; ++i) - MeshTools::subdivide(indices(), normals(0), [](const Vector3& a, const Vector3& b) { - return (a+b).normalized(); - }); - - MeshTools::removeDuplicates(indices(), normals(0)); - positions(0)->assign(normals(0)->begin(), normals(0)->end()); - } + /** + * @brief Solid icosphere + * @param subdivisions Number of subdivisions + * + * Indexed @ref Mesh::Primitive "Triangles" with normals. + */ + static Trade::MeshData3D solid(UnsignedInt subdivisions); }; }}