Debian Codegraph @

libs/filamentapp/include/filamentapp/IcoSphere.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
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 //TNT_FILAMENT_SAMPLE_ICOSPHERE_H