Atoms Crowd  4.1.0
Mesh.h
1 #pragma once
2 // ===========================================================================
3 // Copyright (c) 2015 Toolchefs Ltd. All rights reserved.
4 //
5 // Use of this software is subject to the terms of the Toolchefs license
6 // agreement provided at the time of installation or download, or which
7 // otherwise accompanies this software in either electronic or hard copy form.
8 // ===========================================================================
9 
10 #include <AtomsUtils/Globals.h>
11 #include <AtomsUtils/AtomsMath.h>
12 #include <AtomsUtils/Triangle.h>
13 #include <vector>
14 #include <map>
15 
16 //#define ATOMS_USE_MESH_BVH 1
17 
18 namespace AtomsUtils
19 {
20  class Bvh;
21  class KdTreeAccel;
22 
24 
29  class ATOMSUTILS_EXPORT Mesh
30  {
31  public:
32 
33  enum GridMode
34  {
35  kKdtree = 0,
36  kBvh = 1
37  };
38 
39  struct UVData
40  {
41  std::string name;
42  std::vector<AtomsMath::Vector2f> uvs;
43  std::vector<unsigned int> uvIndices;
44  };
45 
47  Mesh();
48 
50  virtual ~Mesh();
51 
53  Mesh(const Mesh& rhs);
54 
56  Mesh& operator=(const Mesh& rhs);
57 
59  bool hasGrid() { return m_grid != nullptr; };
60 
62  inline std::vector<AtomsMath::Vector3f>& points();
63 
64  inline const std::vector<AtomsMath::Vector3f>& points() const;
65 
67  inline std::vector<AtomsMath::Vector3f>& normals();
68 
69  inline const std::vector<AtomsMath::Vector3f>& normals() const;
70 
72  inline std::vector<unsigned int>& indices();
73 
74  inline const std::vector<unsigned int>& indices() const;
75 
77  inline std::vector<unsigned int>& vertexCount();
78 
79  inline const std::vector<unsigned int>& vertexCount() const;
80 
82  inline std::vector<AtomsMath::Vector2f>& uvs();
83 
84  inline const std::vector<AtomsMath::Vector2f>& uvs() const;
85 
87  inline unsigned int numberOfFaces() const;
88 
90  inline unsigned int numberOfVertices() const;
91 
93  inline std::vector<AtomsMath::Vector3f>& jointWeights();
94 
96  inline const std::vector<AtomsMath::Vector3f>& jointWeights() const;
97 
99  inline std::vector<AtomsMath::Vector3i>& jointIndices();
100 
102  inline const std::vector<AtomsMath::Vector3i>& jointIndices() const;
103 
105  inline std::vector<UVData>& uvSets();
106 
108  inline const std::vector<UVData>& uvSets() const;
109 
111  void buildIntersectionGrid(short gridMode = kKdtree);
112 
114  void multiplyPointsByMatrix(const AtomsMath::Matrix &matrix);
115 
117  virtual bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float &param, unsigned int &outFaceId, float& outU, float &outV, bool bothDirection = false) const;
118 
120  virtual bool closestPoint(const AtomsMath::Vector3f& inP, AtomsMath::Vector3f& outP, unsigned int& outFaceId, float& outU, float& outV, float& sqrDistance) const;
121 
123  virtual bool isInside(const AtomsMath::Vector3f& point) const;
124 
126  void clear();
127 
130 
133 
135  void triangulate();
136 
138  void transform(const AtomsMath::Matrixf &matrix);
139 
141  void merge(Mesh& inMesh);
142 
144  void createBox(const AtomsMath::Box3f& b);
145 
147  void createPlane(const AtomsMath::Box2f& b, const AtomsMath::Vector2i& divisions);
148 
149  public:
150 
151  static void triangulateMesh(const Mesh& input, Mesh& output);
152 
153  private:
154 
156  std::vector<AtomsMath::Vector3f> m_points;
157 
159  std::vector<AtomsMath::Vector3f> m_normal;
160 
162  std::vector<unsigned int> m_indices;
163 
165  std::vector<unsigned int> m_vertexCount;
166 
168  std::vector<AtomsMath::Vector2f> m_uvs;
169 
171  std::vector<AtomsMath::Vector3f> m_jointWeights;
172 
174  std::vector<AtomsMath::Vector3i> m_jointIndices;
175 
177  std::vector<UVData> m_uvSets;
178 
180  void* m_grid;
181 
182  short m_gridMode;
183 
184  };
185 
186 }
187 
188 #include "Mesh.impl.h"
189 
AtomsUtils::Mesh::triangulate
void triangulate()
Triangulate.
AtomsUtils::Mesh::Mesh
Mesh()
Constructor.
AtomsUtils::Mesh::Mesh
Mesh(const Mesh &rhs)
Copy constructor.
AtomsUtils::Mesh::buildIntersectionGrid
void buildIntersectionGrid(short gridMode=kKdtree)
Build kd tree.
AtomsUtils::Mesh::isInside
virtual bool isInside(const AtomsMath::Vector3f &point) const
Check if a point is inside this mesh.
AtomsUtils
AtomsCore namespace.
Definition: Base64.h:13
AtomsUtils::Mesh::UVData
Definition: Mesh.h:40
AtomsUtils::Mesh::multiplyPointsByMatrix
void multiplyPointsByMatrix(const AtomsMath::Matrix &matrix)
Multiply all points by the given matrix.
AtomsUtils::Mesh::intersect
virtual bool intersect(const AtomsMath::Vector3f &orig, const AtomsMath::Vector3f &dir, float &param, unsigned int &outFaceId, float &outU, float &outV, bool bothDirection=false) const
intersect
AtomsUtils::Mesh::operator=
Mesh & operator=(const Mesh &rhs)
Assign operator.
AtomsUtils::Mesh::closestPoint
virtual bool closestPoint(const AtomsMath::Vector3f &inP, AtomsMath::Vector3f &outP, unsigned int &outFaceId, float &outU, float &outV, float &sqrDistance) const
Closets point.
AtomsUtils::Mesh::transform
void transform(const AtomsMath::Matrixf &matrix)
Transform.
AtomsUtils::Mesh::hasGrid
bool hasGrid()
Check if it has underlying kdtree grid.
Definition: Mesh.h:59
AtomsUtils::Mesh::clear
void clear()
Clear mesh data.
AtomsUtils::Mesh
Mesh class.
Definition: Mesh.h:30
AtomsUtils::Mesh::~Mesh
virtual ~Mesh()
Destructor.
AtomsUtils::Mesh::createBox
void createBox(const AtomsMath::Box3f &b)
Create a box.
AtomsUtils::Mesh::createPlane
void createPlane(const AtomsMath::Box2f &b, const AtomsMath::Vector2i &divisions)
Create a plane.
AtomsUtils::Mesh::clearIntersectionGrid
void clearIntersectionGrid()
Clear the intersection grid.
AtomsUtils::Mesh::computeSoftEdgeNormals
void computeSoftEdgeNormals()
Compute averaged face vertex normals.
AtomsUtils::Mesh::merge
void merge(Mesh &inMesh)
Merge a mesh.