summaryrefslogtreecommitdiff
path: root/thirdparty/thekla_atlas/nvmesh/TriMesh.h
blob: bc5672c1ac4be276764b0c94b87492c822f59700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// This code is in the public domain -- Ignacio Castaño <castano@gmail.com>

#pragma once
#ifndef NV_MESH_TRIMESH_H
#define NV_MESH_TRIMESH_H

#include "nvcore/Array.h"
#include "nvmath/Vector.inl"
#include "nvmesh/nvmesh.h"
#include "nvmesh/BaseMesh.h"

namespace nv
{
    /// Triangle mesh.
    class TriMesh : public BaseMesh
    {
    public:
        struct Face;
        typedef BaseMesh::Vertex Vertex;

        TriMesh(uint faceCount, uint vertexCount) : BaseMesh(vertexCount), m_faceArray(faceCount) {}

        // Face methods.
        uint faceCount() const { return m_faceArray.count(); }
        const Face & faceAt(uint i) const { return m_faceArray[i]; }
        Face & faceAt(uint i) { return m_faceArray[i]; }
        const Array<Face> & faces() const { return m_faceArray; }
        Array<Face> & faces() { return m_faceArray; }

        NVMESH_API Vector3 faceNormal(uint f) const;
        NVMESH_API const Vertex & faceVertex(uint f, uint v) const;

        friend Stream & operator<< (Stream & s, BaseMesh & obj);

    private:

        Array<Face> m_faceArray;

    };


    /// TriMesh face.
    struct TriMesh::Face
    {
        uint id;
        uint v[3];
    };

} // nv namespace

#endif // NV_MESH_TRIMESH_H