Atoms Crowd  7.0.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 
150  void createSphere(float radius, unsigned int sectorCount, unsigned int stackCount);
151 
153  void createPyramid(float radius, float height, unsigned int faceCount);
154 
156  void createDisk(float radius, unsigned int sectorCount);
157 
160 
161  AtomsMath::Box3f boundingBox(const AtomsMath::Matrixf& matrix) const;
162 
163  public:
164 
165  static void triangulateMesh(const Mesh& input, Mesh& output);
166 
167  private:
168 
170  std::vector<AtomsMath::Vector3f> m_points;
171 
173  std::vector<AtomsMath::Vector3f> m_normal;
174 
176  std::vector<unsigned int> m_indices;
177 
179  std::vector<unsigned int> m_vertexCount;
180 
182  std::vector<AtomsMath::Vector2f> m_uvs;
183 
185  std::vector<AtomsMath::Vector3f> m_jointWeights;
186 
188  std::vector<AtomsMath::Vector3i> m_jointIndices;
189 
191  std::vector<UVData> m_uvSets;
192 
194  void* m_grid;
195 
196  short m_gridMode;
197 
198  };
199 
200 }
201 
202 #include "Mesh.impl.h"
203 
Mesh class.
Definition: Mesh.h:30
void createBox(const AtomsMath::Box3f &b)
Create a box.
void createDisk(float radius, unsigned int sectorCount)
Create a disk.
void createSphere(float radius, unsigned int sectorCount, unsigned int stackCount)
Create a sphere.
void clear()
Clear mesh data.
void createPlane(const AtomsMath::Box2f &b, const AtomsMath::Vector2i &divisions)
Create a plane.
void merge(Mesh &inMesh)
Merge a mesh.
void transform(const AtomsMath::Matrixf &matrix)
Transform.
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
void clearIntersectionGrid()
Clear the intersection grid.
void buildIntersectionGrid(short gridMode=kKdtree)
Build kd tree.
void multiplyPointsByMatrix(const AtomsMath::Matrix &matrix)
Multiply all points by the given matrix.
Mesh & operator=(const Mesh &rhs)
Assign operator.
bool hasGrid()
Check if it has underlying kdtree grid.
Definition: Mesh.h:59
void changeWindingOrder()
Change winding order.
virtual ~Mesh()
Destructor.
void computeSoftEdgeNormals()
Compute averaged face vertex normals.
void createPyramid(float radius, float height, unsigned int faceCount)
Create a pyramid.
Mesh(const Mesh &rhs)
Copy constructor.
Mesh()
Constructor.
virtual bool closestPoint(const AtomsMath::Vector3f &inP, AtomsMath::Vector3f &outP, unsigned int &outFaceId, float &outU, float &outV, float &sqrDistance) const
Closets point.
void triangulate()
Triangulate.
virtual bool isInside(const AtomsMath::Vector3f &point) const
Check if a point is inside this mesh.
AtomsCore namespace.
Definition: Base64.h:13
Definition: Mesh.h:40