blob: c8559511f12f5684fecabec878a9b11bd2c8a545 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
// This code is in the public domain -- Ignacio Castaño <castano@gmail.com>
#pragma once
#ifndef NV_MESH_BASEMESH_H
#define NV_MESH_BASEMESH_H
#include "nvmesh.h"
#include "nvmath/Vector.h"
#include "nvcore/Array.h"
#include "nvcore/Hash.h"
namespace nv
{
/// Base mesh without connectivity.
class BaseMesh
{
public:
struct Vertex;
BaseMesh() {}
BaseMesh(uint vertexNum) :
m_vertexArray(vertexNum) {}
// Vertex methods.
uint vertexCount() const { return m_vertexArray.count(); }
const Vertex & vertexAt(uint i) const { return m_vertexArray[i]; }
Vertex & vertexAt(uint i) { return m_vertexArray[i]; }
const Array<Vertex> & vertices() const { return m_vertexArray; }
Array<Vertex> & vertices() { return m_vertexArray; }
friend Stream & operator<< (Stream & s, BaseMesh & obj);
protected:
Array<Vertex> m_vertexArray;
};
/// BaseMesh vertex.
struct BaseMesh::Vertex
{
Vertex() : id(NIL), pos(0.0f), nor(0.0f), tex(0.0f) {}
uint id; // @@ Vertex should be an index into the vertex data.
Vector3 pos;
Vector3 nor;
Vector2 tex;
};
inline bool operator==(const BaseMesh::Vertex & a, const BaseMesh::Vertex & b)
{
return a.pos == b.pos && a.nor == b.nor && a.tex == b.tex;
}
inline bool operator!=(const BaseMesh::Vertex & a, const BaseMesh::Vertex & b)
{
return a.pos != b.pos && a.nor != b.nor && a.tex != b.tex;
}
template <> struct Hash<BaseMesh::Vertex>
{
uint operator()(const BaseMesh::Vertex & v) const
{
return Hash<Vector3>()(v.pos);
}
};
} // nv namespace
#endif // NV_MESH_BASEMESH_H
|