operations.hh 684 Bytes
Newer Older
Philip Trettner's avatar
Philip Trettner committed
1
2
3
4
5
6
7
8
9
10
11
12
#pragma once

#include "../Mesh.hh"

#include <glm/glm.hpp>

// Basic mesh operations, including:
// - elementary subdivision
// - intersections

namespace polymesh
{
Philip Trettner's avatar
Philip Trettner committed
13
14
/// Given a flat polymesh with convex faces, naively triangulates all faces
void triangulate_naive(Mesh& m);
Philip Trettner's avatar
Philip Trettner committed
15

Philip Trettner's avatar
Philip Trettner committed
16
/// ======== IMPLEMENTATION ========
Philip Trettner's avatar
Philip Trettner committed
17

Philip Trettner's avatar
Philip Trettner committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
void triangulate_naive(Mesh& m)
{
    std::vector<vertex_handle> vs;
    for (auto f : m.faces())
    {
        vs = f.vertices().to_vector();
        if (vs.size() <= 3)
            continue;

        // remove
        m.faces().remove(f);

        // triangulate
        for (auto i = 2u; i < vs.size(); ++i)
            m.faces().add(vs[0], vs[1], vs[i]);
    }
}
Philip Trettner's avatar
Philip Trettner committed
35
}