| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#ifndef TNT_FILAMENT_SAMPLE_ICOSPHERE_H |
| 18 |
#define TNT_FILAMENT_SAMPLE_ICOSPHERE_H |
| 19 |
|
| 20 |
#include <math/vec3.h> |
| 21 |
|
| 22 |
#include <map> |
| 23 |
#include <vector> |
| 24 |
|
| 25 |
class IcoSphere { |
| 26 |
public: |
| 27 |
using Index = uint16_t; |
| 28 |
|
| 29 |
struct Triangle { |
| 30 |
Index vertex[3]; |
| 31 |
}; |
| 32 |
|
| 33 |
using TriangleList = std::vector<Triangle>; |
| 34 |
using VertexList = std::vector<filament::math::float3>; |
| 35 |
using IndexedMesh = std::pair<VertexList, TriangleList>; |
| 36 |
|
| 37 |
explicit IcoSphere(size_t subdivisions); |
| 38 |
|
| 39 |
IndexedMesh const& getMesh() const { return mMesh; } |
| 40 |
VertexList const& getVertices() const { return mMesh.first; } |
| 41 |
TriangleList const& getIndices() const { return mMesh.second; } |
| 42 |
|
| 43 |
private: |
| 44 |
static const IcoSphere::VertexList sVertices; |
| 45 |
static const IcoSphere::TriangleList sTriangles; |
| 46 |
|
| 47 |
using Lookup = std::map<std::pair<Index, Index>, Index>; |
| 48 |
Index vertex_for_edge(Lookup& lookup, VertexList& vertices, Index first, Index second); |
| 49 |
TriangleList subdivide(VertexList& vertices, TriangleList const& triangles); |
| 50 |
IndexedMesh make_icosphere(int subdivisions); |
| 51 |
|
| 52 |
IndexedMesh mMesh; |
| 53 |
}; |
| 54 |
|
| 55 |
#endif |